Brad
Brad

Reputation: 6105

Controlling psftp in a Windows Batch File

How do I write a batch file to control psftp, but with a dynamic filename? Overall I'm trying to convert a video file and then upload it to my Apple TV. Here's what I have, it generally works, but the commands don't control psftp, psftp just waits for user input:

echo Convert and Upload to Apple TV file Called %1.mkv

ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi

psftp [email protected] -pw aaa
cd downloads/boxee
put %1.avi
quit

I know with the -b flag psftp can call it's own batch file, but I don't know how to get the %1 argument to it. I've seen solutions where a text file is redirected to psftp, but that suffers from the same problem. Also, I'd prefer to have just one file, but having to call a second file would be alright too.

Upvotes: 12

Views: 70052

Answers (6)

descomputer
descomputer

Reputation: 11

I was struggling to run a simple batch file/script to have an end user upload a file she had just edited to a secure FTP site.

Using This Script:

cd /outgoing
put Examplefile.txt
# chmod a+r Examplefile.txt
# ren Examplefile.txt Exam.ted
# rm Examplefile.txt
quit

and running PuTTY's sftp command from a standard Windows command prompt:

psftp [email protected] -pw password -b testscript.scr

I was able to quickly and (more importantly!!) easily upload a file from the company I am doing work for to a company we needed to transact business with. You can also see I am ready to rename the file if needed (ren) or delete a file if needed (rm). The hash symbol (#) sets the lines as remark lines.

This allowed me to create a complete batch file in Windows that the end user could simply click on to upload the files as she generated them. It was MUCH simpler than using some of the other "flavors" of sftp I found on the 'Net and I have used and trusted PuTTY for decades.

Upvotes: 1

Clay
Clay

Reputation: 11605

If all you're doing with ftp is uploading a single file, you can use pscp.

echo Convert and Upload to Apple TV file Called %1.mkv

ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi
pscp -pw aaa -sftp %1.avi [email protected]:/downloads/boxee

Upvotes: 0

alepi
alepi

Reputation: 31

All in one file:

@echo off
echo Convert and Upload to Apple TV file Called %1.mkv
ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi
(
echo cd downloads/boxee
echo put %1.avi
echo quit
) | psftp [email protected] -pw aaa -bc

If we need the precise port number:

psftp [email protected] -P 222 -pw aaa -bc

Upvotes: 3

Lukas
Lukas

Reputation: 49

Specify a file containing batch commands

In normal operation, PSFTP is an interactive program which displays a command line and accepts commands from the keyboard.

If you need to do automated tasks with PSFTP, you would probably prefer to specify a set of commands in advance and have them executed automatically. The -b option allows you to do this. You use it with a file name containing batch commands. For example, you might create a file called myscript.scr containing lines like this:

cd /home/ftp/users/jeff
del jam-old.tar.gz
ren jam.tar.gz jam-old.tar.gz
put jam.tar.gz
chmod a+r jam.tar.gz
quit

and then you could run the script by typing

psftp user@hostname -b myscript.scr

Credit to http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html#6.1.3

Upvotes: 4

Brad
Brad

Reputation: 6105

I ended up creating a new batch file from the main one that I then told psftp to use:

echo cd downloads/boxee > psftp.bat
echo put "%1.avi" >> psftp.bat
echo quit >> psftp.bat

psftp [email protected] -pw aaa -b psftp.bat

Upvotes: 16

Shay Erlichmen
Shay Erlichmen

Reputation: 31928

Why not use the built in FTP command that comes with windows?

you will need to write a script that will upload the file:

open 192.168.1.50
user
frontrow aaa
put file.avi
quit

then call ftp -s:MyScript

You will need to generate the script per each file using echo and the >> redirector.

Upvotes: 1

Related Questions