Jump to content

Trying to make a FTP feature for application. In need of help


Recommended Posts

So the code is, partially there, though this is what i have so far i will be building other features around this. At the moment iam trying to get my script to upload mp3's to my website but im getting a syntax error.

See Below for script

im getting the error at (27,5) : ERROR: syntax error

Any help is appreciated

Edited by ThaReverand

-ThaReverand"http://numerous-silhouettes.com/"

Link to comment
Share on other sites

Please check functions FileOpenDialog or FileSelectFolder.

Your question shows that you urgently need to read the basics about AutoIt. Good sources are the first chapters of the help file, the wiki and some tutorials which can be found on the forum.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Im still having trouble with getting the actual file that is chosen to upload to the server. ive been reading the wiki, but there are no example scripts to work with and im not entirely sure im going about this the right way.

#include <IE.au3>
#include <FTPex.au3>
#include <_ShutDown.au3>

$__ftp_hWinInetDll = DllOpen( 'wininet.dll' )
If $__ftp_hWinInetDll == -1 Then
    ConsoleWrite( "-- ERROR FROM FTPex.au3: Unable to open WinInet.dll" & @LF )
    $__ftp_hWinInetDll = 'wininet.dll'
EndIf

$server = 'SERVERIP'
$username = 'FTPUserName'
$pass = 'FTPPassword'
$port = '21'
$i_Passive = '1'
$uploadmessage = "Hold down Ctrl or Shift to choose multiple files."
$appVersion = "v0.2.3c"

TCPStartup()
;~ AcruX Producer Tool Helper Created by ThaReverand #Trevor Brown#
;~ [url="http://numerous-silhouettes.com"]http://numerous-silhouettes.com[/url]
$ipAddress = @IPAddress1
$portAddress = 666
TrayTip("AcruX-Helper " & $appVersion, "AcruX-Helper Services Started", 4, 1)

Opt("TrayIconHide", 0)


$MainSocket = TCPListen($ipAddress, $portAddress)

$cdStatus = "open"
$driveArray = DriveGetDrive("CDROM")

While 1
  Do
    $ConnectedSocket = TCPAccept($MainSocket)
  Until $ConnectedSocket > 0

  $err = 0
  Do
    $msg = TCPRecv($ConnectedSocket,512)
    $err = @error
    If StringLen($msg) THEN
      ;trayTip("server",$msg, 30)
      
      ; text being sent to keyboards...
      if StringInStr ( $msg, "KEYBOARDSEND:") THEN
        $keyboardSendText = StringReplace ( $msg, "KEYBOARDSEND:", "")
        Send ($keyboardSendText, 1)
      endIf
      
      if StringInStr ($msg, "OPENCLOSECD:") THEN  
        For $i = 1 to $driveArray[0]
          CDTray ( $driveArray[$i], $cdStatus)
        Next
        if $cdStatus = "open" THEN
          $cdStatus = "closed"
        else
          $cdStatus = "open"
        endIf
      endIf
      
      if StringInStr ( $msg, "OPENFL:") THEN
        TrayTip("AcruX-Helper " & $appVersion, "Starting Fruity Loops Studio", 4, 1)
        Run ("C:Program FilesImage-LineFL Studio 9FL.exe" ,"",@SW_MAXIMIZE )
      endIf
      
       if StringInStr ( $msg, "CLOSEALL:") THEN
        _ShutDown(3)
        goAway()
     endIf
    
      if StringInStr ( $msg, "QUICKLOGOFF:") THEN
        _ShutDown(0)
     endIf
      
      ;if StringInStr ( $msg, "UPLOAD:") THEN
       ; MsgBox(0, "AcruX-Helper " & $appVersion, "FEATURE COMING SOON")
    ; endIf
      
       ;Uploading Features
      if StringInStr ($msg, "UPLOAD:") THEN  
    $Open = _FTP_Open('AcruX-FTP')
    $Conn = _FTP_Connect($Open, $server, $username, $pass, $i_Passive, $port)
    $Uploadvar = FileOpenDialog($uploadmessage, @WindowsDir & "", "Music (*.mp3;*.zip)")
        If @error Then
            MsgBox(4096,"","No File(s) chosen")
    Else
        $Uploadvar = StringReplace($Uploadvar, "|", @CRLF)
            MsgBox(0,"","You chose " & $Uploadvar)
            $Ftpp = _FTP_FilePut($Conn, $Uploadvar, "/numeroussilhouettes/UploadFolder/" & $Uploadvar)
            $Ftpc = _FTP_Close($Open)
EndIf
EndIf
    
      ; OpenBlog Function
      if StringInStr ( $msg, "BLOG:") THEN
        $oIE = _IECreate ("http://numerous-silhouettes.com/Numerous-Silhouettes/NSP_Blog/NSP_Blog.html", 1)
    ; Check @extended return value to see if attach was successful
        If @extended Then
            MsgBox(0, "AcruX-Helper " & $appVersion, "Opened NSP [BLOG] in Existing Browser instance")
    Else
        MsgBox(0, "AcruX-Helper " & $appVersion, "Opened new NSP [BLOG] instance")
    EndIf
    EndIf

      ; move left
      if StringInStr ( $msg, "MOVELEFT:") THEN
        moveLeft()
      endIf
      
      ; move right
      if StringInStr ( $msg, "MOVERIGHT:") THEN
        moveRight()
      endIf
      
      if StringInStr ( $msg, "EXIT:") THEN
        goAway()
      endIf
      
    endIf

  Until $err
    TCPCloseSocket($ConnectedSocket)
WEnd
; end of the main loop


func goAway()
  TCPShutdown()
  Exit
endFunc

func moveLeft()
  ; set a parameter
  $numPixelsToMove = 15

  $windowArray = WinList()
  For $i = 1 to $windowArray[0][0]
    If $windowArray[$i][0] <> "" AND IsVisible($windowArray[$i][1]) Then
      $posArray = WinGetPos($windowArray[$i][0])
      WinMove ( $windowArray[$i][0], "", $posArray[0]-$numPixelsToMove,   $posArray[1])
    EndIf
  Next
endFunc


func moveRight()
  ; set a parameter
  $numPixelsToMove = 15

  $windowArray = WinList()
  For $i = 1 to $windowArray[0][0]
    If $windowArray[$i][0] <> "" AND IsVisible($windowArray[$i][1]) Then
      $posArray = WinGetPos($windowArray[$i][0])
      WinMove ( $windowArray[$i][0], "", $posArray[0]+$numPixelsToMove,   $posArray[1])
    EndIf
  Next
endFunc

func isVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Here is a excerpt from the actual FTP part for a quicklook

;Uploading Features
      if StringInStr ($msg, "UPLOAD:") THEN  
    $Open = _FTP_Open('AcruX-FTP')
    $Conn = _FTP_Connect($Open, $server, $username, $pass, $i_Passive, $port)
    $Uploadvar = FileOpenDialog($uploadmessage, @WindowsDir & "", "Music (*.mp3;*.zip)")
        If @error Then
            MsgBox(4096,"","No File(s) chosen")
    Else
        $Uploadvar = StringReplace($Uploadvar, "|", @CRLF)
            MsgBox(0,"","You chose " & $Uploadvar)
            $Ftpp = _FTP_FilePut($Conn, $Uploadvar, "/numeroussilhouettes/UploadFolder/" & $Uploadvar)
            $Ftpc = _FTP_Close($Open)
EndIf
EndIf
Edited by ThaReverand

-ThaReverand"http://numerous-silhouettes.com/"

Link to comment
Share on other sites

If the user should be allowed to select more than a single file I would change line

$Uploadvar = FileOpenDialog($uploadmessage, @WindowsDir & "\", "Music (*.mp3;*.zip)")
to
$Uploadvar = FileOpenDialog($uploadmessage, @WindowsDir & "\", "Music (*.mp3;*.zip)", 7)

7 is the sum of following flags:

1 = File Must Exist (if user types a filename)

2 = Path Must Exist (if user types a path, ending with a backslash)

4 = Allow MultiSelect

Then sending of the files needs to be changed. _FTP_FilePut allows to send a single file only.

I would suggest to use StringSplit and then loop through the resulting array and send each single file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks!

While i work on learning Arrays, Lets say for the time being I would want to go about only including one (user defined) file for upload. How would i do that? (Its for another function, before i delve into the other one i'd like to atleast get a grasp on this part.)

So lets say for instance that with what is written, i would have users with this app uploading single zip files for Collaboration purposes, effectively it will be large. But the need to keep all the stems, voices and project files from FL Studio together is urgent.

How would i use whats written with _FTP_FilePut to upload the user defined zip file as a single upload?

Edited by ThaReverand

-ThaReverand"http://numerous-silhouettes.com/"

Link to comment
Share on other sites

Not tested but this should allow to transfer a single file. FileOpenDialog returns the full path of the selected file. Therefore you have to split it into pieces using _PathSplit.

#include <file.au3>
Global $sDrive, $sDir, $sFName, $sExt

;Uploading Features
If StringInStr($msg, "UPLOAD:") Then
    $Uploadvar = FileOpenDialog($uploadmessage, @WindowsDir & "", "Music (*.mp3;*.zip)")
    If @error Then
        MsgBox(4096, "", "No File(s) chosen")
    Else
        MsgBox(0, "", "You chose " & $Uploadvar)
        _PathSplit($Uploadvar, $sDrive, $sDir, $sFName, $sExt)
        $Open = _FTP_Open('AcruX-FTP')
        $Conn = _FTP_Connect($Open, $server, $username, $pass, $i_Passive, $port)
        $Ftpp = _FTP_FilePut($Conn, $Uploadvar, "/numeroussilhouettes/UploadFolder/" & $sFName & $sExt)
        $Ftpc = _FTP_Close($Open)
    EndIf
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

So im just fiddling with the script from above

And i noticed that $Uploadvar was still in the file for upload position

$Ftpp = _FTP_FilePut($Conn, $Uploadvar, "/numeroussilhouettes/UploadFolder/" & $sFName & $sExt)

Should it look like this instead:

$Ftpp = _FTP_FilePut($Conn, $sFName & $sExt, "/numeroussilhouettes/UploadFolder/" & $sFName & $sExt)

Or did you leave $Uploadvar there for a reason instead of using the split path?

or

Should i also include the $sDir like this:

$Ftpp = _FTP_FilePut($Conn, $sDir & $sFName & $sExt, "/numeroussilhouettes/UploadFolder/" & $sFName & $sExt)
Edited by ThaReverand

-ThaReverand"http://numerous-silhouettes.com/"

Link to comment
Share on other sites

According to the help file: "Both $s_LocalFile and $s_RemoteFile may be partial or fully qualified names relative to the current directory."

So I think it is best to specifiy the whole path for the file to be transmitted.

On the FTP server I think you just want the filename + extension.

Example: The User selects "C:temptest.txt" so the statement will resolve to:

$Ftpp = _FTP_FilePut($Conn, "C:temptest.txt", "/numeroussilhouettes/UploadFolder/temp.txt")

Make a small test script with the code and try if it works as you expect.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Ah ok thank you for that clarification

After a bit of tinkering with my ftp account settings (and changing passwords) it works!

Thank you for your help with this water, it has been greatly appreciated :D

Edited by ThaReverand

-ThaReverand"http://numerous-silhouettes.com/"

Link to comment
Share on other sites

You are welcome :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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