Jump to content

FTP Upload!


Recommended Posts

$sPath = @MyDocumentsDir&"\My Received Files\"

$results = _FileFind($sPath, "*.xml", 1)  
If @error = 3 Then
    MsgBox(48, "Attention", "No files found.")
Endif

$ftpIP = '??????'
$ftpUser = '??????'
$ftpPass = '??????'


;Open FTP Session
$dllhandle = DllOpen('wininet.dll')
$Session = _FTPOpen("FTP")
if @error then
    MsgBox(16,"Error","FTP Session Failed to open.")
    DllClose($dllhandle)
    Exit
EndIf

;Connect to FTP server
$ftpSession = _FTPConnect($Session,$ftpIP,$ftpUser,$ftpPass,0,1,0x08000000)
if @error then
    MsgBox(16,"Error","FTP Connection Failed" & @cr & "Please check you connection and FTP Settings")
    _FTPClose($Session)
    DllClose($dllhandle)
    Exit
EndIf
;Send the files
$arraylist = _ArrayCreate ($results)
_FTPPutFile ($ftpSession ,$arraylist, "/www/images",1)

Yeah.. Well I need to be able to upload all my chat logs to my FTP server. But I have to do it not knowing the direct path.

As some of you know, MSN uses random numbers after your username, and the chat logs usernames.

I cannot know these random numbers, and all the logs have to be uploaded.

I am trying to use it with an array, but I don't know what I am doing wrong.

When I try i get the returning number of "0", which on the FTP file, says its incomplete, or error or whatever you want to call it.

Whatever it is, it means it didn't work.

If anyone can help me out with this, that would be kick ass.

Thanks.

Edited by houseonfire
Link to comment
Share on other sites

  • Developers

I think you are trying to upload all found xml files, but $results in your example will contain the handle to the FileFindFirst().

You will need to retrieve all filenames with FileFindNext() and then upload them with:

_FTPPutFile ($ftpSession ,$Filename, "/www/images/"&Filename)

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

You could make life easy by using _FileListToArray() which will create an Array with filenames for you after which you only have to For-Next loop through the list..

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

So each file would have an array name, and id just have to loop through those?

Base example:

#include <File.au3>
$FileList = _FileListToArray("C:\Temp" , "*.xml")
If @error Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
For $x = 1 to $FileList[0]
    ConsoleWrite($FileList[$x] & @CRLF)
Next

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

ERROR

Subscript used with non-Array variable.: 
For $x = 1 to $FileList[0] 
For $x = 1 to $FileList^ ERROR

I get that with

$FileList=_FileListToArray(@MyDocumentsDir&"\My Received Files\", "*.xml")
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
For $x = 1 to $FileList[0]
    ConsoleWrite($FileList[$x] & @CRLF)
Next
_FTPPutFile ($ftpSession ,$FileList, "/www/") 
    If @error Then
        MsgBox(0,"_FTPPutFile @error",@error)
EndIf

I feel like I'm missing something sooo simple and stupid..

Edited by houseonfire
Link to comment
Share on other sites

  • Developers

Try: (Made 2 changes in your code.

$FileList=_FileListToArray(@MyDocumentsDir&"\My Received Files", "*.xml")
If @Error Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
For $x = 1 to $FileList[0]
    ConsoleWrite($FileList[$x] & @CRLF)
Next
_FTPPutFile ($ftpSession ,$FileList, "/www/") 
    If @error Then
        MsgBox(0,"_FTPPutFile @error",@error)
EndIf

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok.. Actually. Someone could help me out a little more... It keeps returning saying that no files were found, even if i give an absolute direct path..

$FileList=_FileListToArray(@DocumentsCommonDir&"My Received Files\", "*.xml")
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

For $x = 1 to $FileList[0]
    ConsoleWrite($FileList[$x] & @CRLF)
Next
_FTPPutFile ($ftpSession ,$FileList, "/www/")
    If @error Then
        MsgBox(0,"_FTPPutFile @error",@error)
EndIf

Edited by houseonfire
Link to comment
Share on other sites

  • Developers

Now why do you think I put that loop in there ? Your FTP task has to go there too since you need to transfer one file at a time.

Don't forget that the target file also needs to be defined.

Something like:

For $x = 1 to $FileList[0]
    ConsoleWrite($FileList[$x] & " tranferred to:" & "/www/"&FileList[$x]  @CRLF)
    _FTPPutFile ($ftpSession ,$FileList[$x], "/www/"&FileList[$x])
    If @error Then
        MsgBox(0,"_FTPPutFile @error",@error)
    EndIf
Next

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...