TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on August 06, 2016, 08:23:41 AM

Title: How to get List of all Files on a FTP Page
Post by: mailmaverick on August 06, 2016, 08:23:41 AM
How to get List of all Files on a FTP Page through autolisp ?
Title: Re: How to get List of all Files on a FTP Page
Post by: ChrisCarlson on August 08, 2016, 08:11:29 AM
Didn't think it was possible to upload / download BUT

Code - Auto/Visual Lisp: [Select]
  1. ;;https://www.theswamp.org/index.php?topic=43337.msg485805#msg485805
  2.   "ftp://user:password@ftp.domain.com//public//sites//www.domain.com//files//"
  3.   "c:\\test.dwg"
  4. )

For a list of files, that would mainly be dependent on the FTP server if it allows say "site list"
Title: Re: How to get List of all Files on a FTP Page
Post by: mailmaverick on August 09, 2016, 11:09:25 AM
Thanks for your reply but I need to get list of files, not put any file.

Also site list is allowed and there is no username and password.

Title: Re: How to get List of all Files on a FTP Page
Post by: dgorsman on August 09, 2016, 03:48:00 PM
Is this some specific location, or just fishing on any random one?
Title: Re: How to get List of all Files on a FTP Page
Post by: mailmaverick on August 11, 2016, 03:32:36 PM
There is my company's internal intranet which I want to explore through LISP.
Title: Re: How to get List of all Files on a FTP Page
Post by: ronjonp on August 11, 2016, 03:40:23 PM
If it's internal, why do you need FTP?
Title: Re: How to get List of all Files on a FTP Page
Post by: VovKa on August 11, 2016, 05:07:30 PM
wget --no-remove-listing ftp://ftp.opera.com/pub/opera/win/1218/en/

wget will create file .listing in its folder
just read it and parse the contents

get it http://gnuwin32.sourceforge.net/packages/wget.htm
Title: Re: How to get List of all Files on a FTP Page
Post by: mailmaverick on August 11, 2016, 06:29:45 PM
If it's internal, why do you need FTP?

Internal means company's files are stored on  a FTP server for use by various people.
Title: Re: How to get List of all Files on a FTP Page
Post by: ronjonp on August 12, 2016, 09:52:28 AM
Gotcha .. so hosted storage.
Title: Re: How to get List of all Files on a FTP Page
Post by: mailmaverick on August 14, 2016, 12:35:41 PM
Thanks Vovka for wget but is it possible in LISP ?

I dont want to modify or put any file but just want list (directory listing) of files.

Please help.
Title: Re: How to get List of all Files on a FTP Page
Post by: VovKa on August 14, 2016, 01:51:11 PM
Thanks Vovka for wget but is it possible in LISP ?
i don't know any means to do this without extra components
Title: Re: How to get List of all Files on a FTP Page
Post by: PKENEWELL on August 15, 2016, 03:10:41 PM
Why not use a Shell interface with the command-line FTP command with DIR and -s:filename? I do not have an FTP to test, but if you could send me an example that I could access, I could give it a try and see if it works.

http://www.nsftools.com/tips/MSFTP.htm
Title: Re: How to get List of all Files on a FTP Page
Post by: mailmaverick on August 15, 2016, 10:56:42 PM
Following example can be used :

ftp://ftp.opera.com/pub/opera/win/1218/en/

Title: Re: How to get List of all Files on a FTP Page
Post by: ChrisCarlson on August 16, 2016, 08:04:43 AM
wget --no-remove-listing ftp://ftp.opera.com/pub/opera/win/1218/en/

wget will create file .listing in its folder
just read it and parse the contents

get it http://gnuwin32.sourceforge.net/packages/wget.htm

This is probably your best bet.
Title: Re: How to get List of all Files on a FTP Page
Post by: PKENEWELL on August 16, 2016, 09:58:12 AM
Following example can be used :

ftp://ftp.opera.com/pub/opera/win/1218/en/

Hmmm. I used NSLOOKUP to get the IP address as required (correction - you can also use a domain) by the FTP program "open" command. I am able to connect to the server you gave, but it will not allow the DIR command unless I "login with USER and PASS". I did not think there was any login requirement. Well - In theory, you should be able to use a Batch file, and direct the output to a text file then read the file back in to a variable in AutoLISP. If you can figure out the proper way to get the info using the FTP command and give me the sequence in a batch file, I will try writing you a routine to run it and retrieve the output.
Title: Re: How to get List of all Files on a FTP Page
Post by: ChrisCarlson on August 16, 2016, 10:27:07 AM
Code: [Select]
[1] site list
[1] 550 Permission denied.
Title: Re: How to get List of all Files on a FTP Page
Post by: PKENEWELL on August 16, 2016, 01:54:05 PM
OK - got this working. It's clunky and slow but it does what the OP wants. Change the variables for paths and ftp information to fit the server and directory needed. NOTE: for some reason, you cannot save the batch file in the same directory as the runftp.txt script or results. it starts an endless loop. I don't know why it would do that.

(Not much for Error checking in this - alter as you will)
Code: [Select]
(defun c:testFTP (/ bpth pth2 ftp ftpp usrn pswd fl wscript cmd exec res rtn)
   (setq bpth "c:\\users\\philk\\"
         pth2 "c:\\users\\philk\\documents\\"
         ftp "ftp.opera.com"
         ftpp "/pub/opera/win/1218/en/"
         usrn "anonymous"
         pswd "myemail@email.com"
   )
   (setq fl (open (strcat bpth "FTP.BAT") "w"))
   (write-line "REM Set the working path" fl)
   (write-line (strcat "cd " pth2) fl)
   (write-line "" fl)
   (write-line "REM Write a Script to run the FTP commands" fl)
   (write-line (strcat "echo open " ftp "> runftp.txt") fl)
   (write-line (strcat "echo user " usrn " " pswd ">> runftp.txt") fl)
   (write-line (strcat "echo cd " ftpp ">> runftp.txt") fl)
   (write-line (strcat "echo dir -r " pth2 "ftpdir.txt>> runftp.txt") fl)
   (write-line "echo bye>> runftp.txt" fl)
   (write-line "" fl)
   (write-line "REM Launch FTP and pass it the script" fl)
   (write-line "ftp -n -s:runftp.txt" fl)
   (write-line "" fl)
   (write-line "REM Clean up." fl)
   (write-line "del runftp.txt" fl)
   (close fl)
   (if (setq wscript (vlax-create-object "WScript.Shell")
             cmd (findfile (strcat bpth "FTP.BAT"))
       )
     (progn
           (setq exec (vlax-invoke wscript 'Exec cmd))
           (while (and exec (= 0 (vlax-get-property exec 'Status)))
                  (princ (strcat "\rWaiting for Program \"" cmd "\"..."))
           )
           (mapcar 'vlax-release-object (list exec wscript))
     )
   )
   (if (setq res (findfile (strcat pth2 "ftpdir.txt")))
      (progn
         (setq fl (open res "r"))
         (while (setq ln (read-line fl))
            (princ (strcat "\n" ln))
            (setq rtn (reverse (cons ln (reverse rtn))))
         )
         (close fl)
      )
   )
   (princ "\n\n")
   rtn
)
Title: Re: How to get List of all Files on a FTP Page
Post by: Andrea on August 20, 2016, 03:10:05 PM
did you tried to map a simple drive to the FTP site with windows..and then....read the file normaly ?
Title: Re: How to get List of all Files on a FTP Page
Post by: PKENEWELL on August 22, 2016, 01:16:17 PM
did you tried to map a simple drive to the FTP site with windows..and then....read the file normaly ?

Yes Interesting :idiot2: :-). I hadn't considered that since I haven't used FTP in ages. Seems like a sensible approach to me. The only drawback is depending on local drive mappings, which in a large user base can be difficult if all mappings are not forced to be the same. If a large company CAD base, the OP or his IT admin would also have to make a login script to establish all the drive mappings to a letter that (hopefully) isn't already mapped by someone. If the OP's CAD user base is relatively small though, it could be relatively easy to setup per user.