2

I need to upload full directory with other directories in it to FTP from Windows PC.

Currently I'm using Windows batch file to upload files to FTP:

FTP -i -s:upload.ftp

Upload.ftp:

open hostname
username
Password
prompt
bin
cd pathonserv/path
prompt
mput localpath/localfolder/*

This code uploads only files from local folder on server but not folders in local folder.

I can use any recommendation. I'm open to changing language from Windows batch file to Python. Also I have Linux terminal features enabled on Windows PC. C++ is also welcome if code can run without any big additional downloads.

Safety is not very important. Currently I prefer speed over safety. I need a simple script to upload directories recursively (with directories in it) to FTP that has username and password.

Also Windows is must! I wouldn't like to have more than 1 downloadable plugin, but even if it will have but work I can take it.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
DrSkull
  • 79
  • 2
  • 11

2 Answers2

4

Just use any other Windows command-line FTP client. Most support recursive transfers.

For example with WinSCP FTP client, you can use the following batch file:

winscp.com /ini=nul /log=upload.log /command ^
    "open ftp://username:password@hostname/" ^
    "put C:\localpath\localfolder\* /pathonserv/path/" ^
    "exit"

WinSCP GUI can even generate a batch file template for you.

There's also a guide for converting Windows FTP script to WinSCP (not that it's really needed in this trivial case).

(I'm the author of WinSCP)


If you want to take a Python way, check Upload folders from local system to FTP using Python script (ignore the accepted answer by @monkut, the answer by @Edgard and some others are better).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
2

This would be the Autoit solution.

;ftp- Upload

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <FTPEx.au3>

$initialPath = 'c:\Users\xxx\Downloads\'

$fileStructure = _FileListToArrayRec($initialPath, '*', $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
;~ _ArrayDisplay($fileStructure)

_Example()

Func _Example()
    Local $sServer = '192.168.178.XXX'
    Local $sUsername = 'admin'
    Local $sPass = 'xxx'
    Local $Err, $sFTP_Message

    Local $hOpen = _FTP_Open('MyFTP Control')
    Local $hConn = _FTP_Connect($hOpen, $sServer, $sUsername, $sPass, 0, 21, $INTERNET_SERVICE_FTP, $INTERNET_FLAG_PASSIVE)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error)
    Else
        _FTP_GetLastResponseInfo($Err, $sFTP_Message)
        ConsoleWrite('$Err=' & $Err & '   $sFTP_Message:' & @CRLF & $sFTP_Message & @CRLF)
        ; do something ...
        _FTP_DirSetCurrent($hConn, '/ALL')
        _FTP_DirPutContents($hConn, $initialPath, '/ALL', 1)
        Sleep(100)
        _FTP_DirSetCurrent($hConn, '/ALL')
        Local $aFile = _FTP_ListToArray($hConn, 0)
        _ArrayDisplay($aFile)
    EndIf
    Local $iFtpc = _FTP_Close($hConn)
    Local $iFtpo = _FTP_Close($hOpen)
EndFunc   ;==>_Example
Xenobiologist
  • 2,091
  • 1
  • 12
  • 16
  • Thanks for your effort! At this moment answer by martyn was accepted. But this works great too. – DrSkull Feb 22 '19 at 13:09