Sign in to follow this  
Followers 0
RickB75

Please tell me where to place this at in this script or if it's wrong

24 posts in this topic

Guys, I been looking and trying to find a FTP script that will work for and I found this on another website here. It should do what I need it to do from looking at it but I'm having trouble placing my server info in it to test it. I don't know where to put the info. I think this is what is suppose to go somewhere

$CmdLine[5]= ["my server info", "my user name", "my password","my dir","my file"]

But it keeps breaking. Any help is always greatly appreciated!!

;
; FTP-Uploader with error correction and notification
;
; @author petzoldj
; @version 0.1
;

#include ;
#include ;
#include ;


; Functions

Func uploadFile($ftp, $server, $user, $password, $dir, $file)
$con = _FTP_Connect($ftp, $server, $user, $password);
$put = _FTP_ProgressUpload($con, $file, $dir & "/" & $file);
Return $con;
EndFunc

Func checkFile($ftp, $con, $dir, $file)
Dim $success = false;
$size = _FTP_FileGetSize($con, $dir & "/" & $file);

If $size > 0 Then
$success = true;
EndIf

Return $success;
EndFunc

Func sendMail($file)
Dim $date = _NowDate();
Dim $time = _NowTime();
Dim $smtp = "MY_SMTP_MAIL_SERVER";
Dim $from = "MY_SENDER";
Dim $sender = "MY_SENDER_MAIL@HOST.COM";
Dim $recipient = "MY_RECIPIENT_MAIL@HOST.COM";
Dim $subject = "MY_SUBJECT";

Dim $body[2];
$body[0] = "MY_MESSAGE_LINE_1";
$body[1] = "MY_MESSAGE_LINE_2";

$mail = _INetSmtpMail($smtp, $from, $sender, $recipient, $subject, $body, @ComputerName, -1);
;$err = @error
;If $mail = 1 Then
; MsgBox(0, "Success!", "Mail sent")
;Else
; MsgBox(0, "Error!", "Mail failed with error code " & $err)
;EndIf
EndFunc

Func init($errorCounter, $ftp, $server, $user, $password, $dir, $file)
$con = uploadFile($ftp, $server, $user, $password, $dir, $file);
$check = checkFile($ftp, $con, $dir, $file);

If $check = false Then
$errorCounter = $errorCounter + 1;
If $errorCounter > 3 Then
;MsgBox(0, "Critical Error", "Upload failes multiple times - terminating");
$mail = sendMail($dir & "/" & $file);
$bye = _FTP_Close($ftp);
Exit;
Else
;MsgBox(0, "Error", "Upload failed - " & $errorCounter & ". attempt");
init($errorCounter, $ftp, $server, $user, $password, $dir, $file);
EndIf
Else
;MsgBox(0, "Finished", "Upload was successful");
EndIf
EndFunc

; Workflow

If $CmdLine[0] < 5 Then
Exit;
EndIf

Const $server = $CmdLine[1];
Const $user = $CmdLine[2];
Const $password = $CmdLine[3];
Const $dir = $CmdLine[4];
Const $file = $CmdLine[5];
Dim $errorCounter = 0;

$ftp = _FTP_Open("FTP Control");
$upload = init($errorCounter, $ftp, $server, $user, $password, $dir, $file);
$bye = _FTP_Close($ftp);

Share this post


Link to post
Share on other sites

john,

Thank you for your reply! I opened the help file and I did find the Command Lind Parameters section. I don't understand it. I'm really green at this. I'm just wondering how I could try this ftp script and see if it would work for me. My goal is to add the FTP portion into a loop in my main script and as a file gets saved locally it then FTPs the file to my server. Right now I'm having to use an external program "FileZilla" to FTP them.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I did find the Command Lind Parameters section. I don't understand it.

Make a google search with the keywords "command line parameters", it's not something specific to autoit.

Edit:

;Replace this:
If $CmdLine[0] < 5 Then
Exit;
EndIf

Const $server = $CmdLine[1];
Const $user = $CmdLine[2];
Const $password = $CmdLine[3];
Const $dir = $CmdLine[4];

;With this:
Global Const $server = "my server info"
Global Const $user = "my user name"
Global Const $password = "my password"
Global Const $dir = "my dir"

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Thank you guys so much for your help. I did change the lines like you suggested Firefox and the script is running it's course but with no luck on the file up load. For the life of me, I can't figure out why I can't get this FTP piece to work. I've tried other scripts and they failed as well. I know the server, User Name and password info is correct. It just won't FTP.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Try the simpliest code possible then, without progress etc and debug it (check the functions return value/@error macro).

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

This is the piece that was recommended I use a couple of months ago.

$host = "my server" ; Hostname of the webserver (Can be a domain name or an IP)
$user = "xxxxxxxxxx" ; FTP Username
$pass = "xxxxxxxxxxx" ; FTP Password
$folder = "/windowsticker" ; This is the folder where your files will upload to

$myFile = "C:\UCC\100.png"
_DebugSetup("Debug", True,2)

$open = _FTP_Open("Myftp")
_DebugOut("FTP Open Return:"&$open)
$conn = _FTP_Connect($open, $host, $user, $pass)
_DebugOut("FTP Connect Return:"&$conn)
;_FTP_Connect($open, $host, $user, $pass,0,0) ;### Debug MSGBOX
$result=_FTP_FilePut($conn, $myFile,"/windowsticker")
_DebugOut("FTP FilePut Return:"&$result&" - Error:"&@error)
_FTP_Close($open)

and this is what I get written back

AutoIt:3.3.8.1 AdminMode (Os:WIN_XP/SP3/X86 OSLang:0409 MUILang:0000 CPUArch:X64)

FTP Open Return:0x00CC0004

FTP Connect Return:0x00CC0008

FTP FilePut Return:0 - Error:-1

+>17:24:01 AutoIT3.exe ended.rc:0

Share this post


Link to post
Share on other sites

BTW, that /100.png is a thumbnail image. very small.

Share this post


Link to post
Share on other sites

I thought it may have been an issue with the firewall but, I can use Filezilla and in the network connections, i can also transfer files from there. I stumped!!

Share this post


Link to post
Share on other sites

Is the full path to your ftp folder "my server/windowsticker"

I never use ftp, but it looks like that might be the problem.

Do you need those double slashes perhaps "my server//windowsticker"

Maybe trailing slashes "my server//windowsticker//" or "my server/windowsticker/"

1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Two things :

-Check if your image full path is correct (FileExists function)

-Try to upload to the root folder: /

After that if it does not work, play with the flags of the function...

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

RickB75,

If "windowsticker" is a directory then your _ftp_fileput stmt should look more like this:

$result=_FTP_FilePut($conn, $myFile,"/windowsticker/" & $my_remote_filename)

where: $my_remote_filename is the name of the file at the remote site

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Here is an example file that I uploaded using Filezilla.

http://www.beaman-auto.com/windowsticker/JTEBU5JR9D5131553.pdf

I need to upload into the windowsticker directory.

Is this right?

$result=_FTP_FilePut($conn, $myFile,"/windowsticker/")

Share this post


Link to post
Share on other sites

ok... This is what I got so far. I did this

$result=_FTP_FilePut($conn, $myFile,"/windowsticker/"&"100.png")

and it did try to upload the image but it has 0 bytes. Any idea why it would do this?

Share this post


Link to post
Share on other sites

Here is an example file that I uploaded using Filezilla.

http://www.beaman-auto.com/windowsticker/JTEBU5JR9D5131553.pdf

I need to upload into the windowsticker directory.

Is this right?

$result=_FTP_FilePut($conn, $myFile,"/windowsticker/")

Try this

$result=_FTP_FilePut($conn, $myFile,"/windowsticker/100.png")


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

It is trying to upload but with each file it has 0 bytes in size. do you think it could be a directory issue on my PC? How would I get / find the true directory for the file I'm trying to upload. right now I'm right clicking on the file and going to the properties and getting it that way. Any ideas?

Share this post


Link to post
Share on other sites

John,

I tried it and getting the same result. It's weird. I'm not doing anything different with the path than when I'm using other scripts.

BTW guys, I just want to thank you for helping me and being patient. It is truly appreciated!

Share this post


Link to post
Share on other sites

I have some scripts that will call data files using the path names and I've never had an issue. It very well could be something on the server side. This is what I get back when I log in using Filezilla.

Status: Resolving address of beaman-auto.com

Status: Connecting to xxx.xxx.xx.xxx.xxxx...

Status: Connection established, waiting for welcome message...

Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------

Response: 220-You are user number 13 of 500 allowed.

Response: 220-Local time is now 18:08. Server port: 21.

Response: 220-This is a private system - No anonymous login

Response: 220 You will be disconnected after 3 minutes of inactivity.

Command: USER xxxxxxxx

Response: 331 User xxxxxxxx OK. Password required

Command: PASS xxxxxxxx

Response: 230 OK. Current restricted directory is /

Command: SYST

Response: 215 UNIX Type: L8

Command: FEAT

Response: 211-Extensions supported:

Response: EPRT

Response: IDLE

Response: MDTM

Response: SIZE

Response: MFMT

Response: REST STREAM

Response: MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;

Response: MLSD

Response: AUTH TLS

Response: PBSZ

Response: PROT

Response: TVFS

Response: ESTA

Response: PASV

Response: EPSV

Response: SPSV

Response: ESTP

Response: 211 End.

Status: Server does not support non-ASCII characters.

Status: Connected

Status: Retrieving directory listing...

Command: CWD /windowsticker

Response: 250 OK. Current directory is /windowsticker

Command: PWD

Response: 257 "/windowsticker" is your current location

Command: TYPE I

Response: 200 TYPE is now 8-bit binary

Command: PASV

Response: 227 Entering Passive Mode (50,63,80,1,197,54)

Command: MLSD

Response: 150 Accepted data connection

Response: 226-Options: -a -l

Response: 226 4941 matches total

Status: Directory listing successful

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

    • Sigmac
      By Sigmac
      I have used this code for a long time, but for a week or 2 it stopped working?
      Connection is ok, the put create the file on server if I delete it on the FTP server, but the file is empty and after 30 secondees the function return 0
      I have tested on 2 machines, Filezilla FTP client have no issue to the server.
      Firewall is disabled under test.
        If $writeFTP = True Then
            $Open=_FTPOpen('MyFTP Control')
            $Conn=_FTPConnect($Open, $destinationServer, $destinationUsername, $destinationPass)
       MsgBox(0,"start","start")
            $Ftpp=_FtpPutFile($Conn, $filePath&$name&".json", "httpdocs/p_calender/" & $name & ".json")
      MsgBox(0,"return","return"&$Ftpp)
      Exit
            $Ftpc=_FTPClose($Open)
           EndIf
       
      From the Lib:
      Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)
          Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
          If @error OR $ai_FTPPutFile[0] = 0 Then
              SetError(-1)
              Return 0
          EndIf
          Return $ai_FTPPutFile[0]
      EndFunc ;==> _FTPPutFile()
       
    • mLipok
      By mLipok
      As for now I was using such kind of snippet:
      Local $aFTP_FileList = _FTP_ListToArray($hFTPSession, 2) For $iFTPFileSize_idx = 1 To $aFTP_FileList[0] ConsoleWrite('Pobieram informacje o pliku:' & $aFTP_FileList[$iFTPFileSize_idx] ) $iWielkoscPliku = _FTP_FileGetSize($hFTPSession, $aFTP_FileList[$iFTPFileSize_idx]) ConsoleWrite($iFTPFileSize_idx & ' : ' & $aFTP_FileList[$iFTPFileSize_idx] & ' rozmiar=' & $iWielkoscPliku) Sleep(200) Next  
      But from some time my clients start buying cheap WD MyCloud NAS, and my problems starts.
      On all others NAS there is no problem (Seagate BlackArmour, QNAP, SYNOLOGY .... ).

      When on list there is for example 20 files then first two of them are very fast checked and reported they FileSize.
      After 2 files there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      .......
       
      In time when I process investigation I checked how :  _FTP_ListToArray2D and _FTP_ListToArrayEx works and I was shocked that they works super fast.
       
      Here are the questions:
      Q1: Why does the problem occur only on WD MyCloud NAS?
      Q2: What is the significant difference that makes using _FTP_ListToArray2D and _FTP_ListToArrayEx to retrieve file sizes is still fast?
      Q3: Why _FTP_FileGetSize() not reporting @errors but returned FileSize = 0 
       
      Regards,
      mLipok
       
    • mLipok
      By mLipok
      In documentation for:
       
      #include <FTPEx.au3> _FTP_Connect ( $hInternetSession, $sServerName, $sUsername, $sPassword [, $iPassive = 0 [, $iServerPort = 0 [, $iService = $INTERNET_SERVICE_FTP [, $iFlags = 0 [, $fuContext = 0]]]]] ) There are two parameters for Passive:
       
      My question is: 

      What is a difference beetwen  using :
      $iPassive = 1
      and
      $iFlags =     $INTERNET_FLAG_PASSIVE
      Regards,
      mLipok
       
    • Xandy
      By Xandy
      Screenshot program that can upload/FTP to website/storage with hotkey.
      Features GUI to display programmable keys.

      Set the hotkeys with this function to use, and display hotkeys.
      ; hotkey_set() Parameters: ; ----------------------------------------------------------- ; $aHotkey -                The array hotkeys are stored in. This function sets the values of this array[hotkey_id][$hotkey_data] ; $dHotkey_id -             The enum for this hotkey index ; $sHotkey_description -     The label displayed to the user to represent function of hotkey ; $sHotkey_name -            The hotkey it'self.  Whatever name string you want to give the key ; $dHotkey_key -             The _IsPressed keycode ;    Keycodes AT: https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm ; $dHotkey_shift -             Shift flag 0 or 1 Default off ; $dHotkey_ctrl -             Ctrl flag 0 or 1 Default off ; $dHotkey_alt -             Alt flag 0 or 1 Default off Func hotkey_set(ByRef $aHotkey, $dHotkey_id, $sHotkey_description, $sHotkey_name, $dHotkey_key, $dHotkey_shift = 0, $dHotkey_ctrl = 0, $dHotkey_alt = 0)     $aHotkey[$dHotkey_id][$eHotkey_data_key_description] = $sHotkey_description     $aHotkey[$dHotkey_id][$eHotkey_data_key_name] = $sHotkey_name     $aHotkey[$dHotkey_id][$eHotkey_data_key] = $dHotkey_key     $aHotkey[$dHotkey_id][$eHotkey_data_shift] = $dHotkey_shift     $aHotkey[$dHotkey_id][$eHotkey_data_ctrl] = $dHotkey_ctrl     $aHotkey[$dHotkey_id][$eHotkey_data_alt] = $dHotkey_alt EndFunc   ;==>hotkey_set ; You can set your hotkeys here ; Please visit the hotkey_set() function for parameter information hotkey_set($aHotkey, $eHotkey_screenshot_ftp, "Selected Window to FTP", "F12", "7B", 0, 1, 0); F12 hotkey_set($aHotkey, $eHotkey_screenshot_disk, "Selected Window to Disk", "S", "53", 1, 1, 1); S hotkey_set($aHotkey, $eHotkey_clipboard_send, "Send Clipboard keystrokes", "F10", "79", 1, 1, 1); F10  
      Configure settings dialog:

      Screenshot Filename and Screenshot Counter, are used to create simple unique filenames that can cycle. Copy URL to clipboard option. - For linking your screenshots. The screenshot file type is for local copy only. App always uses .JPG for FTP right now, but I could add FTP screenshot file type specification.  
      Any suggestions?  Did I break anything, what did I miss?
      Package uses TTS.au3 by Beege: 
       
      FTP_Screen.zip
      File includes:
         - FTP_Screen.au3
         - FTPScreen.ico
         - TTS.au3 - by Beege
    • drorshem
      By drorshem
      Hi,
      I'm looking to create a script which will download all *.txt files from a remote FTP server.
      Once downloaded, delete all *.txt files.
       
      Can this be achieved using AutoIt ?