Sign in to follow this  
Followers 0
YpR^

Is This Possible ? (ftp)

19 posts in this topic

#1 ·  Posted (edited)

Was wondering... is it possible to make this in AutoIT or do i need another language to make it... :ph34r:

A program which open a screen where u can select any file on u'r computer. After selecting the file it'll be uploaded to a specific FTP server with specific login / pass...

Possible or do i need to make it in example Delphi

Edited by YpR^

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

func upload($flnm, $url, $dir, $user, $pass)
    delwait(@ScriptDir & "\upload.txt")
    $ftfile = FileOpen(@ScriptDir & "\upload.txt", 2)
    If $ftfile <> - 1 Then
        FileWriteLine($ftfile, 'open ' & $url)
        FileWriteLine($ftfile, $user)
        FileWriteLine($ftfile, $pass)
        if $dir <> "" Then
            FileWriteLine($ftfile, 'cd ' & $dir)
        EndIf
        FileWriteLine($ftfile, 'binary')
        FileWriteLine($ftfile, 'put "' & FileGetShortName($flnm) & '"')
        FileWriteLine($ftfile, 'bye')
    EndIf
    FileClose($ftfile)
    RunWait('ftp -s:"' & FileGetShortName(@ScriptDir & '\upload.txt') & '"', '', @SW_HIDE)
    FileDelete(@ScriptDir & "\upload.txt")
EndFunc

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

thank you... im pretty new to this :ph34r: .. so .. which "unit's" do i have to change ?

($flnm, $url, $dir, $user, $pass) in first line ?


Share this post


Link to post
Share on other sites

    delwait(@ScriptDir & "\upload.txt")

<{POST_SNAPBACK}>

You are missing the delwait function in your scipt....

:ph34r:


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

well... dont understand much of this :ph34r: .. but... what do i do if i wan't to send a file to this specification's:

FTP: ftp://autoit-is-fun.net

USER: Auto

PASS: It

Do i need other specification's to send ?

Yes... im getting some error's when trying to run it..

something with the delwait(@ScriptDir & "\upload.txt")


Share this post


Link to post
Share on other sites

Here is my ftp script - watch line wrapping!!

;*******************************************************************************************

;** This Script transfers a file from my Unix box to my PC. It accepts user input

;** of a filename and a directory on the Unix machine and uses this to create

;** a text file called ftp.ftp. This is then used to run the command line ftp

;** program supplied with windows. It is a basically wrapper for Microsoft command line Ftp

;*******************************************************************************************

;** Get Filename and Directory

$answer1 = InputBox("File Transfer", "Enter Name of File required : ","excusinv.dbf")

$answer2 = InputBox("Default Directory","Enter Default Directory : ","/u/foxbase/data")

StringLower($Answer1)

;** Bomb out on nul input

if @error <> 0 or $answer1="" then

msgbox(0,"Message","Bye bye")

exit

endif

;** Create ftp parameters file

FileOpen ( "ftp.ftp", 2 )

FileWriteline( "ftp.ftp", "username" )

FileWriteline( "ftp.ftp", "password" )

FileWriteline( "ftp.ftp", "cd " & $answer2 )

FileWriteline( "ftp.ftp", "binary" )

FileWriteline( "ftp.ftp", "get " & $answer1 )

FileWriteline( "ftp.ftp", "quit" )

fileclose("ftp.ftp")

;** Run ftp program

RunWait(@ComSpec & " /c " & 'ftp -s:ftp.ftp 192.168.1.200', "", @SW_HIDE)

exit

just change "get " to "send " and it will send a file to the specified directory. Have added a lot of notes to help you understand the script.

This was my first ever script, when my samaba server went down it saved my bacon!!!

Steve

Share this post


Link to post
Share on other sites

Here is my ftp script - watch line wrapping!!

;*******************************************************************************************

;** This Script transfers a file from my Unix box to my PC.  It accepts user input

;** of a filename and a directory on the Unix machine and uses this to create

;** a text file called ftp.ftp.  This is then used to run the command line ftp

;** program supplied with windows.  It is a basically wrapper for Microsoft command line Ftp

;*******************************************************************************************

;** Get Filename and Directory

$answer1 = InputBox("File Transfer", "Enter Name of File required : ","excusinv.dbf")

$answer2 = InputBox("Default Directory","Enter Default Directory : ","/u/foxbase/data")

StringLower($Answer1)

;** Bomb out on nul input

if @error <> 0 or $answer1="" then

  msgbox(0,"Message","Bye bye")

  exit

 

endif

;** Create ftp parameters file

FileOpen ( "ftp.ftp", 2 )

FileWriteline( "ftp.ftp", "username" )

FileWriteline( "ftp.ftp", "password" )

FileWriteline( "ftp.ftp", "cd "  & $answer2 )

FileWriteline( "ftp.ftp", "binary" )

FileWriteline( "ftp.ftp", "get " & $answer1 )

FileWriteline( "ftp.ftp", "quit" )

fileclose("ftp.ftp")

;** Run ftp program

RunWait(@ComSpec & " /c " & 'ftp -s:ftp.ftp 192.168.1.200', "", @SW_HIDE)

exit

<{POST_SNAPBACK}>

Some of it which i dont understand 100 % ....

If i would send a file example a txt file on my c: - the ftp-server is ftp://autoit.com - login: auto pass: it .... should it look like this? :

;** Get Filename and Directory

$answer1 = InputBox("File Transfer", "Enter Name of File required : ","123.txt or c:/123.txt ?")

$answer2 = InputBox("Default Directory","Enter Default Directory : ","/ <--- this for home directory ?")

StringLower($Answer1)

;** Bomb out on nul input

if @error <> 0 or $answer1="" then

msgbox(0,"Message","Bye bye")

exit

endif

;** Create ftp parameters file

FileOpen ( "ftp.ftp", 2 )

FileWriteline( "ftp.ftp", "auto" )

FileWriteline( "ftp.ftp", "it" )

FileWriteline( "ftp.ftp", "cd " & $answer2 )

FileWriteline( "ftp.ftp", "binary" )

FileWriteline( "ftp.ftp", "send <--- " & $answer1 )

FileWriteline( "ftp.ftp", "quit" )

fileclose("ftp.ftp")

;** Run ftp program

RunWait(@ComSpec & " /c " & 'ftp -s:ftp.ftp 192.168.1.200', "", @SW_HIDE) <-- don't fully understand this ... am i going to write the ftp-adress here ?

exit

thank you :ph34r:


Share this post


Link to post
Share on other sites

@jdeb, Yes. It is simply a function to check whether or not a file was deleted on the first pass and if not, wait until delete works. I have updated the original post.


Who else would I be?

Share this post


Link to post
Share on other sites

i understand **** of this.... im pretty newbie :ph34r: ... oh well..

//this-is-me .... do i have to decompile the script and cahnge the file to be uploaded every time i want to send a new file ? :S

and what value's in ur script do i have to change ?


Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

The important part of the script is:

ftp -s:ftp.ftp 192.168.1.200

This runs program ftp, feeds a simple parameter file (I called it ftp.ftp) and specifies the IP address of the machine.

example of ftp.ftp parameter file

(My script mainly generates the following:)

user

password

cd /cd/2remote/machine/directory

binary

send file1.dbf

get file2.dbf

quit

This is username, password, cd command to change directory on remote - see below, binary changes the

file transfer type, send file1.dbf from currently active directory on your pc, get file2.dbf from the directory on remote machine from the directory cd to earlier , then quit

This may help

Syntax

ftp [-v] [-d] [-i] [-n] [-g] [-s:FileName] [-a] [-w:WindowSize] [-A] [Host]

Parameters

-v Suppresses the display of FTP server responses.

-d Enables debugging, displaying all commands passed between the FTP client and FTP server.

-i Disables interactive prompting during multiple file transfers.

-n Suppresses the ability to log on automatically when the initial connection is made.

-g Disables file name globbing. Glob permits the use of the asterisk (*) and question mark (?) as wildcard characters in local file and path names. For more information, see Ftp: Glob.

-s:FileName Specifies a text file that contains ftp commands. These commands run automatically after ftp starts. This parameter allows no spaces. Use this parameter instead of redirection (<).

-a Specifies that any local interface can be used when binding the FTP data connection.

-w:WindowSize Specifies the size of the transfer buffer. The default window size is 4096 bytes.

-A Logs onto the FTP server as anonymous.

Host Specifies the computer name, IP address, or IPv6 address of the FTP server to which to connect. The host name or address, if specified, must be the last parameter on the line.

/? Displays help at the command prompt.

Examples

To log on to the FTP server named ftp.example.microsoft.com, type the following command:

ftp ftp.example.microsoft.com

To anonymously log on to the FTP server named ftp.example.microsoft.com, type the following command:

ftp -A ftp.example.microsoft.com

To log on to the FTP server named ftp.example.microsoft.com and run the ftp commands contained in a file named Resynch.txt, type the following command:

This looks ike the syntax you need:

ftp -s:resynch.txt ftp.example.microsoft.com

The above is from the windows xp help files.

If you still can't get it to work email me direct on xirconuk at yahoo dot co dot uk with full details and I will have a play!!!

Steve

Edited by xircon

Share this post


Link to post
Share on other sites

THANK U SO MUCH STEVE :ph34r: ... working now...


Share this post


Link to post
Share on other sites

is it possible to make:

RunWait(@ComSpec & " /c " & 'ftp -s:ftp.ftp "192.168.1.200" <--- this part', "", @SW_HIDE) like

FileWriteline( "ftp.ftp", "cd " & $answer2 ) <--- u have a "variable" $answer2 .... can u make the ftp-server address variable too ? ... and make a:

$answerx = InputBox("FTP-server", "FTP-serverrequired : ","test.com")


Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

is it possible to make:

RunWait(@ComSpec & " /c " & 'ftp -s:ftp.ftp "192.168.1.200"  <--- this part', "", @SW_HIDE) like

FileWriteline( "ftp.ftp", "cd "  & $answer2 ) <--- u have a "variable" $answer2 .... can u make the ftp-server address variable too ? ... and make a:

$answerx = InputBox("FTP-server", "FTP-serverrequired : ","test.com")

<{POST_SNAPBACK}>

You could store stuff to variables, write the proper FTP commands to a text file, close the file handle, and feed that to the DOS FTP command, sure. Although at that rate, it would probably be eaisier to use a real FTP client, such as FileZilla since it will give you a true user interface. Plus you don't have to worry about the full remote server path, which often times you can't guess. Prompting for it before you connect to the server in your AutoIt code will not allow the user to browser the directory, but will require that they have the entire server directory structure memorized.

BB tag fix

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Is it possible to "instead of placing the file in same folder" to make a dialog like the attachment ? ... so u can "pick" the file instead

Edited by YpR^

Share this post


Link to post
Share on other sites

Try:

$ANSWER=FileOpenDialog( "Please choose a File", "c:\", "All (*.*)")

Steve

Share this post


Link to post
Share on other sites

Where in the code should i paste / overwrite ?


Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

hmm.... dosen't upload anything.. :/.... Do i really have to but the file to upload in the same folder ? :ph34r:

Edited by YpR^

Share this post


Link to post
Share on other sites

hmm.... dosen't upload anything.. :/.... Do i really have to but the file to upload in the same folder ? :ph34r:

<{POST_SNAPBACK}>

No, but you will need to specify either the full path to the file, or the relative path from your CWD (Current Working Directory.) If you don't know the CWD in a DOS shell, you can type 'cd' and it will tell you. You could also cd to the location where the souce is before you upload it, and that would eliminate the need for paths. The same rule could apply for FTP downloads from the commandline.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

pekster >> could u give me a "script phrase" ?


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