473,575 Members | 3,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sftp problem!


I want to use sftp from paramiko to copy a file from a windows machine to a
Linux in the network, I use this code :

host = "LinuxComputerN ame" (or its Ip)
port = 22
transport = paramiko.Transp ort((host, port))
password = "LinuxComputerP assword"
username = "LinuxComputerU serName"

transport.conne ct(username = username, password = password)
sftp = paramiko.SFTPCl ient.from_trans port(transport)
filepath = '/home/test.jpg'
localpath = '/home/test.jpg'
sftp.get(filepa th, localpath)

sftp.close()
transport.close ()

and after runing this code I get this error:
socket.error: (10061, 'Connection refused')

What is wrong with this code?
please help me.

--
View this message in context: http://www.nabble.com/sftp-problem%2...p19821106.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Oct 5 '08 #1
4 4703
In message <ma************ *************** ***********@pyt hon.org>, sa6113
wrote:
host = "LinuxComputerN ame" (or its Ip)
port = 22

and after runing this code I get this error:
socket.error: (10061, 'Connection refused')
Did you try

sftp LinuxComputerNa me

just to confirm it's got a listener on port 22?
Oct 5 '08 #2

what do you mean?
Lawrence D'Oliveiro wrote:
>
In message <ma************ *************** ***********@pyt hon.org>, sa6113
wrote:
>host = "LinuxComputerN ame" (or its Ip)
port = 22

and after runing this code I get this error:
socket.error : (10061, 'Connection refused')

Did you try

sftp LinuxComputerNa me

just to confirm it's got a listener on port 22?
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/sftp-problem%2...p19823566.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Oct 5 '08 #3
here is a snippet that works, you need to replace the default data or
create a database etc.. and the fields to store it
you also need to generate and share your public key to the receiving
server to avoid password prompt
# Standard library imports
import os
import sys
import time
import traceback
import paramiko
# my defaultdata is stored in a sqllite table called merchant.lib
# you can just assign values to defaultdata or recreate a database of
your own
from merchant.lib import defaultdata
# set up default values
hostname = defaultdata.def aults['hostname']
username = defaultdata.def aults['username']
password = defaultdata.def aults['password']

# paramiko required data
port = defaultdata.def aults['port']
fname = defaultdata.def aults['fname']
pathupload = defaultdata.def aults['pathupload']
pathdownload = defaultdata.def aults['pathdownload']
input_dir = defaultdata.def aults['input_dir']
output_dir = defaultdata.def aults['output_dir']
curdir = os.path.abspath (os.curdir)

# load ssh pkey you need to precreate the key and ensure the server
side
# has it in its authorized_keys
pkey_path = os.path.expandu ser('~/.ssh/id_dsa')
pkey = paramiko.DSSKey .from_private_k ey_file(pkey_pa th)

paramiko.util.l og_to_file('tra nsfer.log')
logger = paramiko.util.g et_logger('para miko')

try:
# set up connection
t = paramiko.Transp ort((hostname, port))
t.connect(usern ame=username, pkey=pkey)
sftp = paramiko.SFTPCl ient.from_trans port(t)

# upload files
files = [file for file in os.listdir(outp ut_dir)
if file.endswith(' .txt')]
logger.info("UP LOAD FILES %s" % files)
os.chdir(output _dir)
for file in files:
sftp.put(file, os.path.join(pa thupload, file))
os.rename(file, file + '.old')

# download files
response_files = [file for file in sftp.listdir(pa thdownload)
if file.startswith ('DISCOVER_RESP ONSE_')]

logger.info("RE SPOSE FILES: %s" % response_files)
os.chdir(os.pat h.join(curdir, input_dir))
for file in response_files:
file_path = os.path.join(pa thdownload, file)
sftp.get(file_p ath, file)
sftp.remove(fil e_path)
# close connection
t.close()
Oct 6 '08 #4

Dear Mike,
Thanks for your help, but I am new in paramiko,would you please help me
more?

May I connect to server by password insted of private key? How?
I used this code:
....
t.auth_password (username, password, event)
....
but I received this error :
paramiko.SSHExc eption : No existing session

I think my problem is in authentication, Do you think I have to use pycrypto
module or something like that??

If not would you please tell me how should I precreate the key and ensure
the server
side has it in its authorized_keys ? How do I share that as I mentioned it
before I am using two different platforms?

Thanks.

Mike Hjorleifsson wrote:
>
here is a snippet that works, you need to replace the default data or
create a database etc.. and the fields to store it
you also need to generate and share your public key to the receiving
server to avoid password prompt
# Standard library imports
import os
import sys
import time
import traceback
import paramiko
# my defaultdata is stored in a sqllite table called merchant.lib
# you can just assign values to defaultdata or recreate a database of
your own
from merchant.lib import defaultdata
# set up default values
hostname = defaultdata.def aults['hostname']
username = defaultdata.def aults['username']
password = defaultdata.def aults['password']

# paramiko required data
port = defaultdata.def aults['port']
fname = defaultdata.def aults['fname']
pathupload = defaultdata.def aults['pathupload']
pathdownload = defaultdata.def aults['pathdownload']
input_dir = defaultdata.def aults['input_dir']
output_dir = defaultdata.def aults['output_dir']
curdir = os.path.abspath (os.curdir)

# load ssh pkey you need to precreate the key and ensure the server
side
# has it in its authorized_keys
pkey_path = os.path.expandu ser('~/.ssh/id_dsa')
pkey = paramiko.DSSKey .from_private_k ey_file(pkey_pa th)

paramiko.util.l og_to_file('tra nsfer.log')
logger = paramiko.util.g et_logger('para miko')

try:
# set up connection
t = paramiko.Transp ort((hostname, port))
t.connect(usern ame=username, pkey=pkey)
sftp = paramiko.SFTPCl ient.from_trans port(t)

# upload files
files = [file for file in os.listdir(outp ut_dir)
if file.endswith(' .txt')]
logger.info("UP LOAD FILES %s" % files)
os.chdir(output _dir)
for file in files:
sftp.put(file, os.path.join(pa thupload, file))
os.rename(file, file + '.old')

# download files
response_files = [file for file in sftp.listdir(pa thdownload)
if file.startswith ('DISCOVER_RESP ONSE_')]

logger.info("RE SPOSE FILES: %s" % response_files)
os.chdir(os.pat h.join(curdir, input_dir))
for file in response_files:
file_path = os.path.join(pa thdownload, file)
sftp.get(file_p ath, file)
sftp.remove(fil e_path)
# close connection
t.close()
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/sftp-problem%2...p19833497.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Oct 6 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4133
by: Gus M. Creces | last post by:
Hi... I'm looking for some information, technical, white paper - whatever - on how SFTP works. I need to add SFTP capabilities into an app's present FTP capabilities. I'm not really looking for a 3rd party solution, like a plug in. Would prefer to write the code in C++ or C#. Just haven't found much technical information on the topic. ...
4
2422
by: Luke Vogel | last post by:
I've looked everywhere ... Is there anywhere that has the source code for a SFTP client that I can modify for my needs? Please? -- Regards Luke. -----
0
4669
by: Bernhard Günther | last post by:
Hello friends of php, PhP-Version is 4 on a FreeBSD-System using apache. Got a problem using ssh2.sftp. Installed correctly (libssh2, ssh2.so-module). Connecting with publickey works, sftp subsystem-connect works too:
7
15376
by: RadhakrishnanR | last post by:
How i can implement SFTP in VB. Scenario is I want to take file from SFTP server, then after some process with the file , file will be moved to database.. Our requirement is very clear that how to use SFTP in VB, currently we are using the OS-native FTP functionality, for SFTP there is no OS-native functionality. And we are not using any...
1
2180
by: bir | last post by:
I need to SFTP the files from one Windows 2003 Server (primary) to another Windows 2003 server(secondary) using the perl scripts. Can anyone guide me on this please. I downloaded the SFTP module for ActiveState Perl from CPAN site, problem is - it is dependent on many others modules! 1.Do i need to download all the modules and install...
12
15650
by: jcor | last post by:
Hi, I'm using Ubuntu 7.04. I'm writing a sript that sends files via ftp for several destinations. So far I used Net::FTP and it worked fine. My problem is that I need to send files via SFTP (SSH2). I've been trying to install Net::SFTP with 'sudo perl -MCPAN -e "install NET::SFTP' but I can't. It stops in the middle of the installation: ...
0
1871
by: arkascha | last post by:
Helloooo everyone, I have a problem with a small solution I made some three or four years ago. Worked flawless until deployed onto newer machines now and guess what, I cannot fix it. Maybe some guru here can give this a look and tell a stupid newbie like me what I miss... The strategy is to have some kind of a shell-like wrapper and work...
2
3818
by: sivashanmugam | last post by:
Hi Friends, I tried to send some zips from local to remote location but the transfer is not sucess i can transfer the zips partially can some one assist me how to make it as sucess i had used the below code #!/bin/sh /usr/local/bin/expect <<EOF
1
8267
by: ndedhia1 | last post by:
I was hoping you could help me out with ftp vs sftp. Below is a method that I have that I call to ftp files from one unix box to another in house, but soon, we will have to ftp from here to NY so we have to start using sftp. I know that we have open ssh on our unix boxes but was wondering how different the syntax would be, going from ftp to...
0
8120
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7868
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6515
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2286
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1382
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1107
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.