Jump to content

FTP functions not working.


Recommended Posts

#include <FTP.au3>

$server = 'ftp://jrankin3.12gbfree.com'
$username = 'username'
$pass = 'password'

$Open = _FTPOpen('MyFTP')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpp = _FTPPutFile($Conn, 'doc.txt', '/doc2.txt')
MsgBox(0,0,$Ftpp)
;$FtpMD = _FTPMakeDir($Conn, "/asdf")
$Ftpc = _FTPClose($Open)

I could upload the file using ftp commands, but I don't know how to go about sending them in autoit. The current code I have now isn't working, and yes I can connect to the ftp server with an ftp client and upload the file I need to upload, but I want to do it once an hour or so, without being disturbed by a window popping up, or something of the sort.

What am I doing wrong?

EDIT: note: the ftpmakedir isn't needed, I was just seeing if it would work, and it didn't (the code right there might be wrong)

EDIT2: Tried using ftpxxx.au3, wouter's old ftp functions, the _ftpadv() one, and no luck.

Edited by Kickassjoe

What goes around comes around... Payback's a bitch.

Link to comment
Share on other sites

Downloaded this off the forum some time ago. Not sure where it is from but the UDF credits GtaSpider. I have not tested this, but it would be nice to know if it works for you.

;SEND EXAMPLE
_FileSend(@ScriptDir&"\ICON (0).ico",@IPAddress1);Sendet die datei cmd.exe an die IP adresse @IPAdress1(Also an die eigene)
If @error Then MsgBox(48,"","Error: "&@error)
_FileSend(@ScriptDir&"\ICON (0).ico","192.168.2.1",4444,0,0);Sendet die datei cmd.exe an die IP adresse 192.168.0.1 über port 4444, Splashtext wird nicht angezeigt und wenn er beim ersten mal Connecten fehlschlägt bricht er ab.
If @error Then MsgBox(48,"","Error: "&@error)

;===============================================================================
;
; Function Name:   _FileSend
; Description:: Sending a File to an Server (See _FileReceive)
; Parameter(s):   
;$sFile  : The File to send
;$IP                        : The target IP Adress
;$PORT [Optional]        : The Port to use (must be the same as by _FileRecevie!!)
;$iSplash [Optional]            : 1(defaul) = show SplashText
;                   0 = dont show SplashText
;$iWaitWhileConnected [Optional]    : 0 = If TCPConnect faild (@error) Return with error Code 2
;                   1(Default) = If TCPConnect faild put it in a while until connected
; Requirement(s):  -
; Return Value(s):  On Succes Return 1
;        On faild Return -1 and @error code 1-3:
;        @error = 1: File not exist
;        @error = 2: TCPConnect faild (only able if $iWaitWhileConnected <> 1)
;        @error = 3: Faild to Open File
;        @error = 4: A Connectionproblem while sending
; Author(s):       GtaSpider
;
;===============================================================================
 
Func _FileSend($sFile, $IP, $PORT = 4444,$iSplash=1, $iWaitWhileConnected = 1)
    Local $iMainSocket = -1, $sBuff, $iFileOp,$sRecv
   
    If Not FileExists($sFile) Then Return SetError(1,0,-1)
    If $iSplash Then $iSplash = SplashTextOn('','Try To Connect...',200,20,-1,-1,1)
    TCPStartup()
   
    If Number($iWaitWhileConnected) = 1 Then
        While $iMainSocket = -1
            $iMainSocket = TCPConnect($IP, $PORT)
        WEnd
    Else
        $iMainSocket = TCPConnect($IP, $PORT)
        If @error Then Return SetError(2, 0, -1)
    EndIf
    If $iSplash Then ControlSetText($iSplash,'','Static1','Read File...')
    $iFileOp = FileOpen($sFile, 16)
    If @error Then Return SetError(3,0,-1)
    $sBuff = Binary(StringTrimLeft($sFile,StringInStr($sFile,"\",-1,-1))&",")&FileRead($iFileOp)
    FileClose($iFileOp)
    If $iSplash Then ControlSetText($iSplash,'','Static1','Sending File...')
    While BinaryLen($sBuff)
        $iSendReturn = TCPSend($iMainSocket, $sBuff)
        If @error Then Return SetError(4, 0, -1)
        TrayTip('',$iSendReturn,1)
        $sBuff = BinaryMid ($sBuff, $iSendReturn + 1, BinaryLen ($sBuff) - $iSendReturn)
    WEnd
    If $iSplash Then ControlSetText($iSplash,'','Static1','Succesfull!')
    TCPCloseSocket($iMainSocket)
    TCPShutdown()
    Sleep(1000)
    SplashOff()
    Return 1
EndFunc
Link to comment
Share on other sites

#include <FTP.au3>

$server = 'ftp://jrankin3.12gbfree.com'
$username = 'username'
$pass = 'password'

$Open = _FTPOpen('MyFTP')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpp = _FTPPutFile($Conn, 'doc.txt', '/doc2.txt')
MsgBox(0,0,$Ftpp)
;$FtpMD = _FTPMakeDir($Conn, "/asdf")
$Ftpc = _FTPClose($Open)

I could upload the file using ftp commands, but I don't know how to go about sending them in autoit. The current code I have now isn't working, and yes I can connect to the ftp server with an ftp client and upload the file I need to upload, but I want to do it once an hour or so, without being disturbed by a window popping up, or something of the sort.

What am I doing wrong?

EDIT: note: the ftpmakedir isn't needed, I was just seeing if it would work, and it didn't (the code right there might be wrong)

EDIT2: Tried using ftpxxx.au3, wouter's old ftp functions, the _ftpadv() one, and no luck.

Simple add

DllCall("Wininet.dll")

at the beginning of your script

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

I get an @error of 2 with that script, on both _filesend() calls

I also get error 2 with those

_FileSend(@ScriptDir&"\doc.txt","jrankin3.12gbfree.com/",21,0,0)

_FileSend(@ScriptDir&"\doc.txt","ftp://jrankin3.12gbfree.com/",21,0,0)

But I don't think it is my connection, as when I go to ftp://jrankin3.12gbfree.com/ in an internet browser, I get a page.

What goes around comes around... Payback's a bitch.

Link to comment
Share on other sites

DllCall needs 3 parameters, you mean DllOpen? Testing atm.

Still not working with a DllOpen("WinINet.DLL") in the beginning.

Edited by Kickassjoe

What goes around comes around... Payback's a bitch.

Link to comment
Share on other sites

Got it working through the cmd line.

should be easy enough to port to autoit.

ftp ftp://jrankin3.12gbfree.com
username
password
send c:\file.txt /file.txt

is what I put into cmd.

AGH, I forget, what's the command to send things to a cmd??? Looked in the help file and couldn't find it...

Hmm, seems as though ftp commands aren't working through the cmd on Vista, and they are on XP.

Used the IP address instead of the url, everything is working fine now.

Edited by Kickassjoe

What goes around comes around... Payback's a bitch.

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...