cancel
Showing results for 
Search instead for 
Did you mean: 

Connect sftp through python script

Mahesh7225
New Contributor

Hello,
Can you please help me to how to connect ftp server using python script in snaplogic

Thanks
Mahesh

6 REPLIES 6

bojanvelevski
Valued Contributor

Hi @Mahesh7225,

Is there a particular reason not to use the Read & Write snaps for manipulating files on FTP? If you decide to go through Python after all, you’ll need to use the ftplib library. You can find detailed information on how to use it on the following link:

ftplib — FTP protocol client

Regards,
Bojan

Hi bojanvelevski,

Thanks for reply , through read/write/directory browser snap, i am unable to connect to the ftp server (error :- “Unable to create filesystem object for sftp” , message:- “Failed to get SFTP session connected”) so trying to connect through script.

Thanks
Mahesh

Usually it is a syntax error in the SFTP path. It needs to follow the next convention:

sftp://server-name/main-directory/sub-directory/file.txt

If that is ok, re-check your account information.

Mahesh7225
New Contributor

i tried this but still getting error “Reason: _socket.error: [Errno 111] Connection refused in ”

#from com.snaplogic.scripting.language import pysftp
#from import ScriptHook
from ftplib import FTP
from com.snaplogic.scripting.language import ScriptHook
from com.snaplogic.scripting.language.ScriptHook import *

myHostname = “hostname”
myUsername = “username”
myPassword = “password”

ftp = FTP(“hostname”,“22”)
ftp.login(“username”,“password”)"