Sign in to follow this  
Followers 0
nf67

_FTP_FilePut keeps failing :-/

2 posts in this topic

#1 ·  Posted (edited)

This script is supposed to upload the file of which you have the path on the clipboard when Ctrl + Y is pressed.

However, the _FTP_FilePut function keeps failing for unkown reason.

My script gets the FTP information from FTP.conf, so you could try it if you have your own server, but be sure to put FTuP.size on your server (which contains max. allowed file size).

Everything is included in this .zip , the script, a much simpler upload script which does work, FTP.conf and FTuP.size.

Thanks a lot :mellow:

SOLVED: Apparently, when closing a file (_FTP_FileClose) before the transfer, it works fine. So perhaps using _FTP_FilePut while a file is still open results in an error.

Code preview:

#include <FTPEx.au3>
#include <File.au3>
#include <Misc.au3>
#Include <String.au3>
#NoTrayIcon

If _Singleton("FTuP",1) = 0 Then
    Msgbox(0,"FTuP Error:","FTuP is already running!")
    Exit
EndIf

Opt("TrayMenuMode",1)
$HelpItem = TrayCreateItem("Help")
TrayCreateItem("")
$ExitItem = TrayCreateItem("Exit")
TraySetState()

$FileDrive = ""
$FileDir = ""
$FileName = ""
$FileExt = ""

HotKeySet("^y","Upload")

While 1
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
    ContinueLoop
    Case $msg = $HelpItem
    Msgbox(0,"FTuP Help:","Press Ctrl+Y to upload the file of which the path is on the clipboard." &@CRLF& "After the beep, you can use Ctrl+V to paste the link." &@CRLF&@CRLF& _
                    "FTP details are in FTP.conf or encrypted in FTPsecure.conf, sorted by line:" &@CRLF&@CRLF& "1 = FTP Server" &@CRLF& "2 = FTP Account" &@CRLF& "3 = FTP Password" &@CRLF& _
                    "4 = Directory to put the file in, include first and last slash!" &@CRLF& "5 = URL to the folder where the file is placed, include last slash!" &@CRLF&@CRLF& _
                    "If you have both FTP.conf and FTPsecure.conf, then FTPsecure.conf will be used.")
    Case $msg = $ExitItem
    ExitLoop
    EndSelect
WEnd

Func Upload()
    $FilePath = ClipGet()
    If FileExists($FilePath) = 0 Then
        MsgBox(0,"FTuP Error:","The file you want to upload couldn't be found. No FTP connection was made.")
    Else
        If FileExists(@ScriptDir & "\FTPsecure.conf") = 0 Then
            If FileExists(@ScriptDir & "\FTP.conf") = 0 Then
                MsgBox(0,"FTuP Error:","No config file could be found.")
                $NoConfigs = 1
            Else
                $FTPSecure = 0
                $FTPServer = FileReadLine(@ScriptDir & "\FTP.conf",1)
                $FTPAccount = FileReadLine(@ScriptDir & "\FTP.conf",2)
                $FTPPassword = FileReadLine(@ScriptDir & "\FTP.conf",3)
                $FTPDir = FileReadLine(@ScriptDir & "\FTP.conf",4)
                $SiteClip = FileReadLine(@ScriptDir & "\FTP.conf",5)
                $NoConfigs = 0
            EndIf
        Else
            $FTPSecure = 1
            $FTPServer = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",1),"password")
            $FTPAccount = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",2),"password")
            $FTPPassword = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",3),"password")
            $FTPDir = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",4),"password")
            $SiteClip = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",5),"password")
            $NoConfigs = 0
        EndIf

        If $NoConfigs = 0 Then
            $FtpOpen = _FTP_Open("ImageFTP")
            $FtpConnect = _Ftp_Connect($FtpOpen,$FTPServer,$FTPAccount,$FTPPassword)
            If $FtpConnect = 0 Then
                If $FTPSecure = 0 Then
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& $FTPAccount & " + " & $FTPPassword & " on " & $FTPServer)
                Else
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& "Using encrypted FTP details.")
                EndIf
                _FTP_Close($FtpOpen)
            Else
                $FtpFileOpen = _FTP_FileOpen($FtpConnect,$FTPDir & "FTuP.size")
                If $FtpFileOpen = 0 Then
                    MsgBox(0,"FTuP Error:","FTuP.size couldn't be found, it should be on the server in the directory where the files are uploaded" & _
                    " (4th line of the configuration file). It should contain the file size limit in megabytes (MB).")
                    _FTP_Close($FtpOpen)
                Else
                    $FileSize = Round((FileGetSize($FilePath)/1048576),2)
                    $MaxSize = Number(BinaryToString(_FTP_FileRead($FtpFileOpen, 100)))
    ;Close the file before the upload, _FTP_FileClose($FtpFileOpen) .   
                    If $FileSize > $MaxSize Then
                        MsgBox(0,"FTuP Error:","Sorry, that file (" & $FileSize & " MB) exceeds the file size limit (" & $MaxSize & " MB) and will not be uploaded.")
                        _FTP_FileClose($FtpFileOpen) ;Take this out, file will be closed earlier.
                        _FTP_Close($FtpOpen)
                    Else
                        $PathSplit= _PathSplit($FilePath, $FileDrive, $FileDir, $FileName, $FileExt)
                        $File = Random(0,99,1) & $Filename & $FileExt
                        $FilePut = _FTP_FilePut($FtpConnect, $FilePath, $FTPDir & $File)
                        If $FilePut = 0 Then
                            MsgBox(0,"FTuP Error:", "Couldn't put the file on the server, despite a succesful connection.") ;<-- I keep getting this
                            ;MsgBox(0,"$FtpConnect , $FilePath , $FTPDir & $File",$FtpConnect &" , "& $FilePath &" , "& $FTPDir & $File) ;Debug
                            _FTP_FileClose($FtpFileOpen) ;Take this out, file will be closed earlier.
                            _FTP_Close($FtpOpen)
                        Else
                            _FTP_FileClose($FtpFileOpen)
                            _FTP_Close($FtpOpen)
                            ClipPut($SiteClip & $File)
                            Beep(500,100)
                        EndIf
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc
Edited by nf67

Share this post


Link to post
Share on other sites



Anyone :mellow:?

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