Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82502

Re: how to delete my file if exits in the remote server with paramiko?

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 <skip.montanaro@gmail.com>
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 <tencent_75118A3B15CC638478581FA8@qq.com>
References <tencent_75118A3B15CC638478581FA8@qq.com>
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 <skip.montanaro@gmail.com>
To 水静流深 <1248283536@qq.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16945.1418564136.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Sun, Dec 14, 2014 at 6:49 AM, 水静流深 <1248283536@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 = 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: how to delete my file if exits in the remote server with paramiko? Skip Montanaro <skip.montanaro@gmail.com> - 2014-12-14 07:35 -0600

csiph-web