Jump to content

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


Recommended Posts

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);
Link to comment
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.

Link to comment
Share on other sites

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

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

Link to comment
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/"

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

Monkey's are, like, natures humans.

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

Link to comment
Share on other sites

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

Link to comment
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/")
Link to comment
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.

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

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

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

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

×
×
  • Create New...