NassauSky Posted August 25, 2019 Share Posted August 25, 2019 (edited) Hi all, Has anyone used _FTP_FilePut lately. I just can't seem to get it to work. The file does not show up on the ftp server after running the below code. It is able to create the folder "Uploads" on the server yet it can't upload the file and I don't see any errors. expandcollapse popup#include <FTPEx.au3> #include <MsgBoxConstants.au3> #include <Inet.au3> _SendMyFile() Func _SendMyFile() Local $sServer = 'ftp.myftpserver.org' Local $sUsername = 'myaccount' Local $sPass = 'mypassword Local $Err, $sFTP_Message Local $myFile = 'abc.txt' Filedelete ($myFile) Fileopen ($myFile,1) FileWriteLine ($myFile, "ABCDEFG") Fileclose ($myFile) Local $hOpen = _FTP_Open('MyFTP Control') Local $hConn = _FTP_Connect($hOpen, $sServer, $sUsername, $sPass, 1) ;Uses passive mode 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) local $myDir =_FTP_DirCreate ( $hConn, "Uploads" ) _FTP_DirSetCurrent ( $hConn, '/Uploads/' ) _FTP_GetLastResponseInfo($Err, $sFTP_Message) ConsoleWrite('$Err=' & $Err & ' $sFTP_Message:' & @CRLF & $sFTP_Message & @CRLF) local $fileput = _FTP_FilePut($hConn , @ScriptDir & "\abc.txt" , "abc-upload.txt" ) _FTP_GetLastResponseInfo($Err, $sFTP_Message) ConsoleWrite('$Err=' & $Err & ' $sFTP_Message:' & @CRLF & $sFTP_Message & @CRLF) Local $iFtpc = _FTP_Close($hConn) Local $iFtpo = _FTP_Close($hOpen) EndIf Local $iFtpc = _FTP_Close($hConn) Local $iFtpo = _FTP_Close($hOpen) ConsoleWrite('CLOSED CONNECTION AND DONE: $Err=' & $Err & ' $sFTP_Message:' & @CRLF & $sFTP_Message & @CRLF) MsgBox($MB_SYSTEMMODAL, "", "Done FTPing") EndFunc So yes it does create my abc.txt file in my current autoit project folder and it does create the Upload folder on the ftp server but it doesn't create the file. UPDATE: I created a file manually from notepad and saved it into the script folder and it did upload correctly so I'm still stuck on why creating a file in autoit doesn't seem to close a file correctly so that the FTP Upload function works correctly. Hmmm any ideas would be great. Thanks for any help 🙂 Edited August 25, 2019 by nassausky Typo and redundant code and Update Link to comment Share on other sites More sharing options...
NassauSky Posted August 25, 2019 Author Share Posted August 25, 2019 (edited) [SOLVED] OK I got it. I looked more into how to create, open and close files and I noticed I did it so fast I did it wrong. The correct code is here: expandcollapse popup#include <FTPEx.au3> #include <MsgBoxConstants.au3> #include <Inet.au3> _SendMyFile() Func _SendMyFile() Local $sServer = 'ftp.myserver.org' Local $sUsername = 'myuser' Local $sPass = 'mypassword' Local $Err, $sFTP_Message Local $myFile = 'abc.txt' Filedelete ($myFile) $hFile = Fileopen ($myFile,1) FileWriteLine ($myFile, "ABCDEFG") Fileclose ($hFile) Local $hOpen = _FTP_Open('MyFTP Control') Local $hConn = _FTP_Connect($hOpen, $sServer, $sUsername, $sPass, 1) ;Uses passive mode 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) local $myDir =_FTP_DirCreate ( $hConn, "Uploads" ) _FTP_DirSetCurrent ( $hConn, '/Uploads/' ) _FTP_GetLastResponseInfo($Err, $sFTP_Message) ConsoleWrite('$Err=' & $Err & ' $sFTP_Message:' & @CRLF & $sFTP_Message & @CRLF) ;FileChangeDir ( "T:\Temp3\" ) local $fileput = _FTP_FilePut($hConn , @ScriptDir & "\abc.txt" , "abc-upload.txt" ) _FTP_GetLastResponseInfo($Err, $sFTP_Message) ConsoleWrite('$Err=' & $Err & ' $sFTP_Message:' & @CRLF & $sFTP_Message & @CRLF) Local $iFtpc = _FTP_Close($hConn) Local $iFtpo = _FTP_Close($hOpen) EndIf Local $iFtpc = _FTP_Close($hConn) Local $iFtpo = _FTP_Close($hOpen) ConsoleWrite('CLOSED CONNECTION AND DONE: $Err=' & $Err & ' $sFTP_Message:' & @CRLF & $sFTP_Message & @CRLF) MsgBox($MB_SYSTEMMODAL, "", "Done FTPing") EndFunc Thanks autoit 🙂 Edited August 25, 2019 by nassausky Solved Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now