Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'elegant': 0.07; 'subject:file': 0.07; 'bits': 0.09; 'cc:addr:python-list': 0.11; 'wrote:': 0.18; 'server,': 0.19; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'existence': 0.31; 'subject:the': 0.34; 'subject:with': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'two': 0.37; 'remote': 0.38; 'work?': 0.38; 'remove': 0.60; 'simple': 0.61; 'save': 0.62; 'more': 0.64; 'isolate': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=REy1PXFrMMfeB1q/Ph8tppdjHpyl7LOcw5fttI3eh2U=; b=QexJ0ejyC6JV06Yy8+ShmwiVIHcrBZ9c4VNw7CG5KxfGUIUPrYI+6AlKlbvVatZJyQ pVP8Sm83y/AAU65r5rMO1APzMCG3uf+PYOn5mvh4K7TMd93T8Zc145PnJrmfV0MJ8fj/ YJMThFJ8P2U6ItO1WwjRYEey6vgGm+VUYzpusq3LhbUiufB//pWHxmnZdXokhze/ppn9 MPOwbt8GwerRGXUReRcObY6w4OuSK/3t3YZsCERdjspO57QRqilanY84d9kmBgoV6IxM BeY9D3uJWNZIZcsTFaYQccXxYFe9qmYtCTnQnN/N8QrkQX6JkGGeQJLL96z2rjTUX6ky SXZQ== MIME-Version: 1.0 X-Received: by 10.220.250.198 with SMTP id mp6mr15808065vcb.19.1418564127889; Sun, 14 Dec 2014 05:35:27 -0800 (PST) In-Reply-To: References: Date: Sun, 14 Dec 2014 07:35:27 -0600 Subject: Re: how to delete my file if exits in the remote server with paramiko? From: Skip Montanaro To: =?UTF-8?B?5rC06Z2Z5rWB5rex?= <1248283536@qq.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418564136 news.xs4all.nl 2954 [2001:888:2000:d::a6]:51862 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3704 X-Received-Body-CRC: 3189581123 Xref: csiph.com comp.lang.python:82502 On Sun, Dec 14, 2014 at 6:49 AM, =E6=B0=B4=E9=9D=99=E6=B5=81=E6=B7=B1 <1248= 283536@qq.com> wrote: > Is there more elegant way to do the same work? Unlikely. You have two fairly simple bits of code in your example, one to connect to the remote server, the other to check for the file's existence and remove it. The only extra elegance I see is to isolate those two bits of work into separate functions, so you execute something like: sftp =3D connect_via_paramiko("vps ip", 22) remove_remote_file(sftp, "/home/names.txt") Presumably, if you have other work to do on the server, you'd save the sftp object for reuse. Skip