473,463 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Create 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 = "LinuxComputerName" (or its Ip)
port = 22
transport = paramiko.Transport((host, port))
password = "LinuxComputerPassword"
username = "LinuxComputerUserName"

transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
filepath = '/home/test.jpg'
localpath = '/home/test.jpg'
sftp.get(filepath, 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 4681
In message <ma**************************************@python.o rg>, sa6113
wrote:
host = "LinuxComputerName" (or its Ip)
port = 22

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

sftp LinuxComputerName

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**************************************@python.o rg>, sa6113
wrote:
>host = "LinuxComputerName" (or its Ip)
port = 22

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

Did you try

sftp LinuxComputerName

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.defaults['hostname']
username = defaultdata.defaults['username']
password = defaultdata.defaults['password']

# paramiko required data
port = defaultdata.defaults['port']
fname = defaultdata.defaults['fname']
pathupload = defaultdata.defaults['pathupload']
pathdownload = defaultdata.defaults['pathdownload']
input_dir = defaultdata.defaults['input_dir']
output_dir = defaultdata.defaults['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.expanduser('~/.ssh/id_dsa')
pkey = paramiko.DSSKey.from_private_key_file(pkey_path)

paramiko.util.log_to_file('transfer.log')
logger = paramiko.util.get_logger('paramiko')

try:
# set up connection
t = paramiko.Transport((hostname, port))
t.connect(username=username, pkey=pkey)
sftp = paramiko.SFTPClient.from_transport(t)

# upload files
files = [file for file in os.listdir(output_dir)
if file.endswith('.txt')]
logger.info("UPLOAD FILES %s" % files)
os.chdir(output_dir)
for file in files:
sftp.put(file, os.path.join(pathupload, file))
os.rename(file, file + '.old')

# download files
response_files = [file for file in sftp.listdir(pathdownload)
if file.startswith('DISCOVER_RESPONSE_')]

logger.info("RESPOSE FILES: %s" % response_files)
os.chdir(os.path.join(curdir, input_dir))
for file in response_files:
file_path = os.path.join(pathdownload, file)
sftp.get(file_path, file)
sftp.remove(file_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.SSHException : 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.defaults['hostname']
username = defaultdata.defaults['username']
password = defaultdata.defaults['password']

# paramiko required data
port = defaultdata.defaults['port']
fname = defaultdata.defaults['fname']
pathupload = defaultdata.defaults['pathupload']
pathdownload = defaultdata.defaults['pathdownload']
input_dir = defaultdata.defaults['input_dir']
output_dir = defaultdata.defaults['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.expanduser('~/.ssh/id_dsa')
pkey = paramiko.DSSKey.from_private_key_file(pkey_path)

paramiko.util.log_to_file('transfer.log')
logger = paramiko.util.get_logger('paramiko')

try:
# set up connection
t = paramiko.Transport((hostname, port))
t.connect(username=username, pkey=pkey)
sftp = paramiko.SFTPClient.from_transport(t)

# upload files
files = [file for file in os.listdir(output_dir)
if file.endswith('.txt')]
logger.info("UPLOAD FILES %s" % files)
os.chdir(output_dir)
for file in files:
sftp.put(file, os.path.join(pathupload, file))
os.rename(file, file + '.old')

# download files
response_files = [file for file in sftp.listdir(pathdownload)
if file.startswith('DISCOVER_RESPONSE_')]

logger.info("RESPOSE FILES: %s" % response_files)
os.chdir(os.path.join(curdir, input_dir))
for file in response_files:
file_path = os.path.join(pathdownload, file)
sftp.get(file_path, file)
sftp.remove(file_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
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...
4
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
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,...
7
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...
1
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...
12
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...
0
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...
2
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...
1
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
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...
0
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.