跳到主要內容

發表文章

目前顯示的是有「FTP」標籤的文章

[Python] Upload files to FTP

Assume we'd like to upload files to FTP:\\ 192.168.1.12\ Download storage\EXE\ from ftplib import FTP def upload_file_ToFTP ( filename ) : print 'upload:' , filename ftp . storbinary ( 'STOR Download storage \ \ EXE \ \ ' + os . path . basename ( filename ) , open ( filename , 'rb' ) ) #Initialize the FTP setting ftp = FTP ( '192.168.1.12' ) ftp . login ( user = 'OOXX' , passwd = 'SCRETE' ) #get the current working directory cwd = os . getcwd ( ) #get all files from the current working folder files_list = os . listdir ( cwd ) #upload files and skip directories for fn in files_list : #get the full path file name _fn = os.path.realpath(fn) #Skip directories if os . path . isdir ( _fn ) : print 'Skip dir:' , _fn continue upload_file_ToFTP ( _fn ) #upload process completed, close FTP connection ftp . close ( )

[C#] FTP download sample code

If you'd like DL file through  WebRequestMethods, maybe you could try below sample code Input: filePath = "ftp://100.251.237.125/update.xml" targetPath  = update.xml public bool DwonlaodFileFromFTP( string filePath, string targetPath, out string errorMessage)         {             // initialize                      FtpWebRequest request = ( FtpWebRequest ) WebRequest .Create(filePath);             request.Credentials = new NetworkCredential (_user, _password);             request.Proxy = null ;             request.Method = WebRequestMethods . Ftp .DownloadFile;             request.UsePassive = false ; ...

[C#] FtpWebRequest failed

[C#] FtpWebRequest fails  I try to list files using FtpWebRequest but  it fails with a WebException 'The underlying connection was closed: An unexpected error occurred on a receive.'             string ftpPath = "ftp://" + this ._ip;                          FtpWebRequest request = ( FtpWebRequest ) WebRequest .Create(ftpPath);             request.Credentials = new NetworkCredential (_user, _password);             request.Proxy = null ;             request.Method = WebRequestMethods . Ftp .ListDirectory;              FtpWebResponse response = ( FtpWebResponse )request.GetResponse();            ...