Jump to content
Sign in to follow this  
acarter

FTP - Converting DirPutContents to file

Recommended Posts

acarter

Hi all!

So I have the below code, which works perfectly, but it uploads the entire contents of a folder to my server. How would I go about modifying it to take a file in a folder and upload it (rather than the whole folder's contents)?

Thanks in advance! :)

#Include <FTPEx.au3>

FTP()

Func FTP()
    Local $FTPOpen, $FTPConnect, $FTPServer
    Local $User, $Pass, $InstallFolder
    Local $FTPlocation, $FTPUpload, $FTPName
    Local $flag, $INIlocation = "UpdateConfig.ini"
    $flag = 0
    $FTPName = IniRead($INIlocation, "1", "FTP Site", "")
    $FTPServer = IniRead($INIlocation, "1", "Server Name", "My FTP Site")
    $User = IniRead($INIlocation, "1", "Username", "My Username")
    $Pass = IniRead($INIlocation, "1", "Password", "My Password")
    $FTPlocation = IniRead($INIlocation, "1", "FTP Location", "/test/")
    ConsoleWrite("Name: " & $FTPName & " Server: " & $FTPServer & " User: " & $User & " Pass: " & $Pass & " Remote location: " & $FTPlocation)
    $FTPOpen = _FTP_Open($FTPName)
    $FTPConnect = _FTP_Connect($FTPOpen, $FTPServer, $User, $Pass, 1)
    If $FTPConnect <> 0 Then
        MsgBox(0, "Alert", "You must specify the path to the folder to upload", 20)
        $InstallFolder = ("C:\Folder\")
        If @error Then
            $flag = 1
        EndIf
        If $flag = 1 Then
            MsgBox(0, "FTP", "No folder chosen.. Exiting.", 20)
            _FTP_Close($FTPOpen)
            Return
        EndIf
        $FTPUpload = _FTP_DirPutContents($FTPConnect, $InstallFolder, $FTPlocation, 1)
        If $FTPUpload <> 0 Then
            MsgBox(0, "FTP", "File(s) successfully uploaded!", 20)
        Else
            MsgBox(0, "FTP", "File(s) were not successfully uploaded! Check your FTP location and try again.", 10)
        EndIf
    Else
        MsgBox(0, "FTP", "Please check the FTP settings and try again. Error Code: " & $FTPConnect & " @error:" & @error, 100)
    EndIf
    _FTP_Close($FTPOpen)
EndFunc

Share this post


Link to post
Share on other sites
acarter

Forgot to add, I changed DirPutContents to DirPutFile(with correct parameters)  and it errors out on upload - the error is "File(s) were not successfully uploaded" message box.

Share this post


Link to post
Share on other sites
acarter

Fixed it. Needed to change the path to upload to include the file name and not just the directory.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.