Sign in to follow this  
Followers 0
JonBMN

[RESOLVED]Having trouble connecting with _FTP_Connect()

5 posts in this topic

#1 ·  Posted (edited)

Right now I'm trying to connect to a server to upload a file directory, which will be chosen by me once the connection is made. I've checked my FTP settings and it seems that the error is spouting from _FTP_Connect(). Can anyone give me an idea of why my script is not working, or point me in the right direction?

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", "")
    $User = IniRead($INIlocation, "1", "Username", "")
    $Pass = IniRead($INIlocation, "1", "Password", "")
    $FTPlocation = IniRead($INIlocation, "1", "FTP Location", "")
    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 = FileSelectFolder("Open", @WorkingDir)
        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   ;==>FTP
Edited by JonBMN

Share this post


Link to post
Share on other sites



Is the FTP server using sFTP by any chance? I'm not sure that the FTP functions work with sFTP servers. Or you might need to change the port setting for the server and see if that works.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I will check that out and post back soon.

Share this post


Link to post
Share on other sites

I needed to change the name of the server I was connecting to, From xxxxx.local to either Server.xxxxxx.local or just Server, since it was on my local network. Otherwise that function can be used to help people upload folders to their FTP server using a .ini file to dynamically read in values for _FTP_Open and _FTP_Connect. Also the FTP Location setting is used to put it in a specified folder on the server, as it will only take the contents of a folder, not the base folder.

Share this post


Link to post
Share on other sites

Glad you got it working. :thumbsup:

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  
Followers 0

  • Similar Content

    • falcontechnics
      By falcontechnics
      Hello,
       
      When a script started as shown below, the “modified time/dates” of the files inside the directory changes as the time/date of “Starting ftp transfer” Accordingly this sutiation times/dates at host seems like all recived in same moment.
       
      Could you please help me to fix this problem ?
       
      Thanks in advance.
      #include <File.au3>
      #include <FTPEx.au3>;
      FileFindFirstFile("c:\qmc\senddata\qmc_cmm\*.*" )
            If  not @error = 1 Then
                         Local $putCMM  = _FTP_DirPutContents ($Conn, "c:\qmc\senddata\qmc_cmm", '/DataSmithJr/Result/Assembly/CMM',1)
                         If $putCMM = 0 Then
                              exit
                        EndIf
                      EndIf