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โ€)"