New to FTP (FTP Batch in one File)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

New to FTP (FTP Batch in one File)

#1 Post by Meerkat » 28 Jul 2015 09:02

Hi again!

I am new (and currently experimenting) on FTP "scripts". I also want to make the script inside a batch file, so I came up with this:

Code: Select all

@echo off
set "site=ftp.microsoft.com"  ...Just a sample FTP site

(
echo.open %site%
echo.dir
)| ftp -A

pause


...I succeeded on downloading an image file (other website) using that. The only problem is that it only works on "Anonymous login". Without the -A switch...

Output:

Code: Select all

User (ftp.microsoft.akadns.net:(none)): Password:


Is there a way to also automate the login? Any help will be appreciated. Cheers! :D

Meerkat
Last edited by Meerkat on 29 Jul 2015 02:48, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: New to FTP

#2 Post by foxidrive » 28 Jul 2015 09:16

Does this post give you enough info?

viewtopic.php?p=42216#p42216

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: New to FTP

#3 Post by Meerkat » 28 Jul 2015 11:32

Hmmm... I figured it out.

To automate login... add -n to ftp to suppress auto-login, then
add user FTP command to login!

Code: Select all

@echo off
set "site=ftp.microsoft.com"  ...Just a sample FTP site

(
echo.open %site%
echo.user anonymous password
echo.dir
echo.bye
)| ftp -n

pause


I just posted this for reference. Thanks!

Meerkat
Last edited by Meerkat on 28 Jul 2015 23:19, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: New to FTP

#4 Post by foxidrive » 28 Jul 2015 22:20

Squashman wrote:Interesting. I have never thought of piping commands to FTP. I always just make a script on the fly.


Good point, I'm glad you commented. I was too tired to see the significance myself.
I'm tired now too - I thought I double posted and deleted your post by mistake. Oops. :oops:

Nice find Meerkat!

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: New to FTP (FTP Batch in one File)

#5 Post by Meerkat » 09 Aug 2015 02:47

The same setup also works in DISKPART command:

Code: Select all

@echo off

(
   echo.list disk
   echo.list disk
)|diskpart

echo.
echo.
echo Does it worked?

pause


Output

Code: Select all

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: ---------- (CENSORED)

DISKPART>
  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          298 GB      0 B
  Disk 1    Online           14 GB      0 B

DISKPART>
  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          298 GB      0 B
  Disk 1    Online           14 GB      0 B

DISKPART>

Does it worked?
Press any key to continue . . .


Meerkat

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: New to FTP

#6 Post by Squashman » 14 Oct 2015 09:43

foxidrive wrote:
Squashman wrote:Interesting. I have never thought of piping commands to FTP. I always just make a script on the fly.


Good point, I'm glad you commented. I was too tired to see the significance myself.
I'm tired now too - I thought I double posted and deleted your post by mistake. Oops. :oops:

Nice find Meerkat!


I finally got around to testing this out as I do a ton of automated ftp programs and I usually just create a ftp script file on the fly and then execute FTP with the S: option.

While piping the commands to FTP.exe works it does not allow you to capture a log file of the session. Now 99.9% of the time I normally do not have a problem with our automation. But if for some reason it failed the first thing I look at is the verbose output in the ftp log file. I guess I will have to decide how it important it is to have that. I lean more towards having the log file.

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: New to FTP (FTP Batch in one File)

#7 Post by npocmaka_ » 14 Oct 2015 11:24

A little offtopic
Here's trick that allows you to get the long name of the last in the path directory with piping to ftp:

>echo lcd C:\ASDQWE~1\ZXCASD~1|ftp
Local directory now C:\ASDQWE~1\zxcasdzxczxc.
Last edited by npocmaka_ on 14 Oct 2015 13:07, edited 1 time in total.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: New to FTP (FTP Batch in one File)

#8 Post by Squashman » 14 Oct 2015 12:36

npocmaka_ wrote:A little offtopic
Here's trick that allows you to get the long name of the last in the path directory with piping to ftp:

>echo \ASDQWE~1\ZXCASD~1|ftp
Local directory now C:\ASDQWE~1\zxcasdzxczxc.

:?: :?:

Post Reply