Batch equivalent for bash with mac terminal

user5934139

I need some help converting this following code from Batch to Bash for my Mac. It is just a simple program which gets files from my computer to put into an ftp server:

In the batch file:

ftp -s:FTP.txt ftp.example.com

In the FTP.txt file:

*user*
*password*
cd /files/
put "C:\Users\*username*\Pictures\image.jpg"

So I have almost got the equivalent, with help of a few hours of research, but need some help still:

#!/bin/sh
HOST='ftp.example.com'
USER='*user*'
PASS='*password*'
FILE='/Users/*username*/Desktop/image.jpg'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASS
cd /files/
put $FILE
quit
END_SCRIPT

This just doesn't quite work, it logs in, then changes the current directory, but says:

local: /Users/*username*/Desktop/image.jpg remote: /Users/*username*/Desktop/image.jpg 
Can't open that file: No such file or directory.

Then proceeds to logs out. I have checked over the directory path, and it's completely fine, I can even open another terminal and do cd /Users/username/Desktop/image.jpg and it works.

Any help is appreciated, thanks.

Mark Setchell

The problem is that when you do:

put /Users/*username*/Desktop/image.jpg

it is trying to create a file on your server called

/Users/*username*/Desktop/image.jpg

but there is probably no directory called /Users/.../Desktop on your FTP server to put it in and it will not create the path itself.

What you actually need to do, is add the name of the file on the server where you want the uploaded file to be stored, like this:

put /Users/*username*/Desktop/image.jpg  NEW.jpg

Also, you should quote variables, so you would want:

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASS
cd /files/
put "$FILE" NEW.jpg
quit
END_SCRIPT

Alternatively, you can avoid passing a full path to the FTP server by locally changing directory first, so you would do:

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASS
cd /files/
lcd "$USER/Desktop"
put image.jpg
quit
END_SCRIPT

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mac: gnome-terminal equivalent for shell script

From Dev

batch rename files on ftp server using mac terminal

From Dev

What is the equivalent of "-" from Bash in Windows batch?

From Dev

Batch file equivalent of PIPESTATUS

From Dev

Mac OS X Terminal Error -bash: [-f: command not found

From Dev

MAC 10.10 Yosemite - Terminal: - bash: [SomeCommand] command not found?

From Dev

Mac Terminal batch file rename: flip string and digits

From Dev

Mac terminal -bash command not found?

From Dev

Batch rename files in mac os x bash with regexp

From Dev

Mac terminal error -bash: command not found - El Capitan 10.11.13

From Dev

Windows batch equivalent of bash script using conditional "IF statement"

From Dev

Unicode special characters not working on Mac OSX 10.11.5 bash terminal

From Dev

Terminal mac (bash) script to extract, move and clean a WordPress install

From Dev

how to use fzf on Mac Terminal with bash

From Dev

Restart bash from terminal without restarting the terminal application (mac)?

From Dev

Bash scripts are not working but on mac terminal those commands in scripts works

From Dev

Mac Terminal (Bash) batch program to get multimedia file info using ffmpeg

From Dev

MAC 10.10 Yosemite - Terminal: - bash: [SomeCommand] command not found?

From Dev

Batch file equivalent in Linux

From Dev

Bash $PS1 collapsing in MAC terminal

From Dev

Mac Terminal batch file rename: flip string and digits

From Dev

Mac terminal bash “command not found”

From Dev

Batch rename files in mac os x bash with regexp

From Dev

Mac terminal error -bash: command not found - El Capitan 10.11.13

From Dev

Windows batch equivalent of bash script using conditional "IF statement"

From Dev

Mac equivalent .bat file to perform terminal functions

From Dev

Terminal color codes not working in bash on my mac

From Dev

changing file names of larger subset in bash (mac Terminal)

From Dev

How to set Intellij Idea Terminal to git bash on mac os

Related Related

  1. 1

    Mac: gnome-terminal equivalent for shell script

  2. 2

    batch rename files on ftp server using mac terminal

  3. 3

    What is the equivalent of "-" from Bash in Windows batch?

  4. 4

    Batch file equivalent of PIPESTATUS

  5. 5

    Mac OS X Terminal Error -bash: [-f: command not found

  6. 6

    MAC 10.10 Yosemite - Terminal: - bash: [SomeCommand] command not found?

  7. 7

    Mac Terminal batch file rename: flip string and digits

  8. 8

    Mac terminal -bash command not found?

  9. 9

    Batch rename files in mac os x bash with regexp

  10. 10

    Mac terminal error -bash: command not found - El Capitan 10.11.13

  11. 11

    Windows batch equivalent of bash script using conditional "IF statement"

  12. 12

    Unicode special characters not working on Mac OSX 10.11.5 bash terminal

  13. 13

    Terminal mac (bash) script to extract, move and clean a WordPress install

  14. 14

    how to use fzf on Mac Terminal with bash

  15. 15

    Restart bash from terminal without restarting the terminal application (mac)?

  16. 16

    Bash scripts are not working but on mac terminal those commands in scripts works

  17. 17

    Mac Terminal (Bash) batch program to get multimedia file info using ffmpeg

  18. 18

    MAC 10.10 Yosemite - Terminal: - bash: [SomeCommand] command not found?

  19. 19

    Batch file equivalent in Linux

  20. 20

    Bash $PS1 collapsing in MAC terminal

  21. 21

    Mac Terminal batch file rename: flip string and digits

  22. 22

    Mac terminal bash “command not found”

  23. 23

    Batch rename files in mac os x bash with regexp

  24. 24

    Mac terminal error -bash: command not found - El Capitan 10.11.13

  25. 25

    Windows batch equivalent of bash script using conditional "IF statement"

  26. 26

    Mac equivalent .bat file to perform terminal functions

  27. 27

    Terminal color codes not working in bash on my mac

  28. 28

    changing file names of larger subset in bash (mac Terminal)

  29. 29

    How to set Intellij Idea Terminal to git bash on mac os

HotTag

Archive