- NSIS Discussion
- Install files directly on a FTP Server
Archive: Install files directly on a FTP Server
Sp33dy G0nz4l3s
1st November 2006 10:39 UTC
Install files directly on a FTP Server
Hello,
is it possible to upload files directly on a FTP Server?
If it is.. is there perhaps anywhere an example?
I've seen this installer but I don't now if that's NSIS:
http://www.cs-erweiterungen.de/3.jpg
Thank you :)
Sp33dy G0nz4l3s
1st November 2006 14:55 UTC
Yes, I've already used the forum search. I've only found this ftpul-plugin:
http://forums.winamp.com/showthread....ght=ftp+upload
But unfortunately it is unstable.. and in the installation one can't define a host..
The plugin inetc(lient) looks very good but this is only to download from a FTP. Right?
Gives it an other plugin which I've not seen?
Thank you
kichik
1st November 2006 15:03 UTC
Originally posted by Sp33dy G0nz4l3s
The plugin inetc(lient) looks very good but this is only to download from a FTP. Right?
Wrong. According to that specific page of thread that I've linked to, it supports FTP upload. And if it doesn't support, or doesn't work, it still suggests an alternative of using ftp.exe from $SYSDIR with the -s switch for scripting.
Takhir
1st November 2006 15:05 UTC
I remember "put" entry point in Inetc plug-in ;) http://nsis.sourceforge.net/Inetc_plug-in
Sp33dy G0nz4l3s
1st November 2006 15:37 UTC
Ah thanks :).. Now I understand these entry points.
But in the example the Username... to the FTP Server are defined in the .nsi:
inetc::put /POPUP /CAPTION "my local ftp upload" "ftp://takhir:pwd@p320/m2.bu.jpg" "$EXEDIR\m2.jpg"
I've no idea how I can make no a custom page like in the picture I posted. So that the user can write the host... in a field and click after this on the connect button and choose the directory.
It would be very friendly if someone could help me.
Takhir
1st November 2006 16:05 UTC
You can define user vars and read current values from custom page ini file to vars, then use them in the command line:
"ftp://$user:$password@$server:$port/$os/$path/$addon"
(if I added port correct :) ). But 'ls' not supported - cannot browse folders. And 'passive' is always 'on'.
Sp33dy G0nz4l3s
1st November 2006 21:51 UTC
Thank you Takhir I will try it :)
But first I've an other question:
My installer consists of a lot of files.
Must I now write to every file the "Upload Code"?
..or gives it the possibility that I indicate a folder and the uploader upload it with all files and subfolders.
Takhir
2nd November 2006 06:55 UTC
You must define every file you want to upload. I remember a lot of FindFirst-FindNext scripts samples in this forum. You also can use SetPluginUnload alwaysoff option - this makes calls a bit faster. Few url/file pairs supported in the single command line, but this may be not usefull in the dir scan loop, and string length limit 1024 bytes also presents.
Sp33dy G0nz4l3s
2nd November 2006 10:41 UTC
Okay.. I've now searched a long time FindFirst-FindNext scripts and I've founded some topics, too. I've also read FindFirst/FindNext in the user manual..
..but I don't understand for what I can use this that I don't must define every file.
Please help me
Sp33dy G0nz4l3s
3rd November 2006 08:35 UTC
Couldn't anybody explain me please how to use FindFirst/FindNext?
Takhir
4th November 2006 20:00 UTC
Something like this
Name "Inetc Dir Scanner Test"
OutFile "scanner.exe"
!include "MUI.nsh"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
!include "FileFunc.nsh"
!insertmacro GetFileAttributes
Section "Dummy Section" SecDummy
FindFirst $0 $1 "$EXEDIR\*"
loop:
StrCmp $1 "" done
${GetFileAttributes} "$EXEDIR\$1" DIRECTORY $2
IntCmp $2 1 cont
Inetc::put ftp://*********.com/$1 "$EXEDIR\$1"
Pop $3
DetailPrint "$1 $3"
cont:
FindNext $0 $1
Goto loop
done:
SetDetailsView show
SectionEnd
If you need recurcive scan - use forum search.
Sp33dy G0nz4l3s
5th November 2006 09:08 UTC
Thanks a lot Takhir!
It works fine. I've now only a little problem:
This is my code now:
;--------------------------------
; General Attributes
Name "Inetc Test"
OutFile "put.exe"
;--------------------------------
;Interface Settings
!include "MUI.nsh"
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install-colorful.ico"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
!include "FileFunc.nsh"
!insertmacro GetFileAttributes
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
SetOutPath "$PROGRAMFILES\TEST"
File "Test1.txt"
File "Test2.txt"
SetOutPath "$PROGRAMFILES\TEST\TEST"
File "TEST\Test3.txt"
FindFirst $0 $1 "$PROGRAMFILES\TEST\*"
loop:
StrCmp $1 "" done
${GetFileAttributes} "$PROGRAMFILES\TEST\$1" DIRECTORY $2
IntCmp $2 1 cont
Inetc::put /POPUP /CAPTION "my local ftp upload" "ftp://*********.com/html/$1" "$PROGRAMFILES\TEST\$1"
cont:
FindNext $0 $1
Goto loop
done:
Pop $3 # return value = exit code, "OK" if OK
MessageBox MB_OK "Upload Status: $3"
SectionEnd
The upload is always shown in the popup window. When I close now this popup window (cancel the upload) normally the MessageBox Upload Status: terminated should be shown and the upload should be terminated.
But with this code always a new upload popup windows is shown and the next file would be uploadet. Could you say me how I must change the code that the upload is then completely terminated?
Thank you
Marc
Takhir
5th November 2006 11:16 UTC
Please note, that in my sample Pop $3 is in loop. This because every Inetc call Pushes one string to stack, so in your variant only last string appears in the MessageBox (all other results remain in stack). So add below plug-in call (not tested)
Pop $3
StrCmp $3 "OK" cont
MessageBox MB_YESNO "Download failed/terminated. Continue?" IDYES cont
Abort "Terminated by user"
cont:
Sp33dy G0nz4l3s
5th November 2006 16:48 UTC
Thanks now it works and I understand it!
Only one question:
With this code now the Installer upload all files from the folder $PROGRAMFILES\TEST:
Section "Dummy Section" SecDummy
SetOutPath "$PROGRAMFILES\TEST"
File "Test1.txt"
File "Test2.txt"
SetOutPath "$PROGRAMFILES\TEST\TEST"
File "TEST\Test3.txt"
FindFirst $0 $1 "$PROGRAMFILES\TEST\*"
loop:
StrCmp $1 "" done
${GetFileAttributes} "$PROGRAMFILES\TEST\$1" DIRECTORY $2
IntCmp $2 1 cont
Inetc::put /POPUP /CAPTION "my local ftp upload" "ftp://*********.com/html/$1" "$PROGRAMFILES\TEST\$1"
Pop $3
StrCmp $3 "OK" cont
MessageBox MB_YESNO "Download failed/terminated. Continue?" IDYES cont
Abort "Terminated by user"
cont:
FindNext $0 $1
Goto loop
done:
SectionEnd
Now the installer should also upload all files from the folder $PROGRAMFILES\TEST\TEST how must I change/extend the code that he do this? I tried a lot of things but nothing has work:
Section "Dummy Section" SecDummy
SetOutPath "$PROGRAMFILES\TEST"
File "Test1.txt"
File "Test2.txt"
SetOutPath "$PROGRAMFILES\TEST\TEST"
File "TEST\Test3.txt"
FindFirst $0 $1 "$PROGRAMFILES\TEST\*"
loop:
StrCmp $1 "" done
${GetFileAttributes} "$PROGRAMFILES\TEST\$1" DIRECTORY $2
IntCmp $2 1 cont
Inetc::put /POPUP /CAPTION "my local ftp upload" "ftp://*********.com/html/$1" "$PROGRAMFILES\TEST\$1"
Pop $3
StrCmp $3 "OK" cont
MessageBox MB_YESNO "Download failed/terminated. Continue?" IDYES cont
Abort "Terminated by user"
cont:
FindNext $0 $1
Goto loop
done:
FindFirst $4 $5 "$PROGRAMFILES\TEST\TEST\*"
loop:
StrCmp $5 "" done
${GetFileAttributes} "$PROGRAMFILES\TEST\TEST\$5" DIRECTORY $6
IntCmp $6 5 cont
Inetc::put /POPUP /CAPTION "my local ftp upload" "ftp://*********.com/html/TEST/$5" "$PROGRAMFILES\TEST\TEST\$5"
Pop $7
StrCmp $7 "OK" cont
MessageBox MB_YESNO "Download failed/terminated. Continue?" IDYES cont
Abort "Terminated by user"
cont:
FindNext $4 $5
Goto loop
done:
SectionEnd
Thanks for your help
Takhir
5th November 2006 17:33 UTC
You can use the same variables in the second part ($0 - $3), but need new labels there, for example loop2 instead of loop (compiller probably says about this in error message). Better way - decorate upload code as a function and call it twice with some variable for path (if 2 folders only to be uploaded). If you want to upload all subfolders - you need a recursive call, I am not sure this is possible in script, but forum search gives this thread http://forums.winamp.com/showthread....sive+findfirst
Sp33dy G0nz4l3s
5th November 2006 19:17 UTC
I understand what you are meaning with call the upload as a function. I've try it but I couldn't create it..
Yes, I would upload all subfolders. I've read so the site from the link you've posted very often but I don't undertstand how i can adapt it in my code.
If someone could help me it would be very friendly.
..otherwise I must define every folder individually like Takhir writes it. Thanks for the help concerning this problem Takhir :)
Comm@nder21
5th November 2006 20:09 UTC
you're missing two things:
1. you only can have one label of the same name in a section or function.
2. you need to close your search after finishing it.
this is the fixed version of your last code listing:
Section "Dummy Section" SecDummy
SetOutPath "$PROGRAMFILES\TEST"
File "Test1.txt"
File "Test2.txt"
SetOutPath "$PROGRAMFILES\TEST\TEST"
File "TEST\Test3.txt"
FindFirst $0 $1 "$PROGRAMFILES\TEST\*"
loop:
StrCmp $1 "" done
${GetFileAttributes} "$PROGRAMFILES\TEST\$1" DIRECTORY $2
IntCmp $2 1 cont
Inetc:ut /POPUP /CAPTION "my local ftp upload" "ftp://*********.com/html/$1" "$PROGRAMFILES\TEST\$1"
Pop $3
StrCmp $3 "OK" cont
MessageBox MB_YESNO "Download failed/terminated. Continue?" IDYES cont
Abort "Terminated by user"
cont:
FindNext $0 $1
Goto loop
done:
FindClose $0
FindFirst $4 $5 "$PROGRAMFILES\TEST\TEST\*"
loop2:
StrCmp $5 "" done2
${GetFileAttributes} "$PROGRAMFILES\TEST\TEST\$5" DIRECTORY $6
IntCmp $6 5 cont2
Inetc:ut /POPUP /CAPTION "my local ftp upload" "ftp://*********.com/html/TEST/$5" "$PROGRAMFILES\TEST\TEST\$5"
Pop $7
StrCmp $7 "OK" cont2
MessageBox MB_YESNO "Download failed/terminated. Continue?" IDYES cont2
Abort "Terminated by user"
cont2:
FindNext $4 $5
Goto loop2
done2:
FindClose $4
SectionEnd
Takhir
6th November 2006 09:05 UTC
It was found ( :) ) that recursion works in NSIS script http://nsis.sourceforge.net/Recursive_Upload
Sp33dy G0nz4l3s
6th November 2006 16:04 UTC
WOW thanks a lot Takhir.
I've now only the problem that I can't upload the files.
I've defined the password, username and server in the variable $url
Example:
Section "Dummy Section" SecDummy
SetDetailsView hide
StrCpy $path "$PROGRAMFILES\TEST"
StrCpy $url ftp://username:pw@server.com/html
Call dirul
SetDetailsView show
SectionEnd
.. but when I start the installer I get always an error and in the details is the following text:
200 Switching to Binary mode.
2Unauthorized (401) C:\Programme\TEST\Test1.txt
terminated by user
Do you know what's wrong?
Thank you
Takhir
6th November 2006 19:51 UTC
What means [url] in you script sample? May be simply
StrCpy $url ftp://username:pwd@server.com/html
Edited: forum' php added [url] to my script too :) BTW I don't see 401 in the
ftp error codes - please check url correctness, plug-in threats it as http. I can test it again in office tomorrow.
Sp33dy G0nz4l3s
6th November 2006 20:22 UTC
Yes that's right.. it's not a ftp error.
I checked the url now again and it sould be correct. Here the url only with an other password:
ftp://web4:pwd@web254.billhost.de/html
I've try the url with the "original" code and there it works.
Thanks for your help :)
Takhir
7th November 2006 07:41 UTC
I fixed one bug (take new version from wiki), but found the problem - all files appears at the same folder. It is possible to modify script and update url as it was done for local file path
Push $path
Push $url
StrCpy $path "$path\$1"
StrCpy $url "$url/$1"
Call dirul
Pop $url
Pop $path
but current plug-in version not creates sub-directories on the ftp server, so folder must exist for this version.
Also, path from 'ftp root' should be used for server, not relative to the user's home folder, for example
ftp://myftp.com/home/user/uploads
And local archive creation and single zip/7z file upload should work as well :)
Sp33dy G0nz4l3s
7th November 2006 20:30 UTC
Takhir, thank you for your help :)
It works now without problems. Unfortunately for my installer it's necessary that the sub-directories would be provided.
Perhaps if you've the time and change sometime the plug-in that it creates the sub-directories it would be very friendly if contact me.. about this thread or a pm.
-Marc
Takhir
12th November 2006 12:57 UTC
New version uploaded, features:
- ftp server path creation for 'put' calls;
- both relative (to user' home dir) and ablolute paths support ("host/path" and "host//path").