Create directory or skip though ftp script - linux
I'm ftping in to an Adrive.com account to upload a backup file. I do not know the version of linux that is installed. I tried to get the version with these commands:
ftp> uname -r
Invalid command.
ftp> cat /etc/*-release
Invalid command.
ftp> lsb_release -a
Invalid command.
ftp> cat /proc/version
Invalid command.
ftp> uname -a
Invalid command.
As you can see none of them worked.
Here is my script that I'm trying to run:
ECHO open ftp://xxx:xxxx#ftp.adrive.com>FTPSND.TXT
echo cd backup>>FTPSND.TXT
echo cd companyfiles>>FTPSND.TXT
echo mkdir %3>>FTPSND.TXT
echo cd %3>>FTPSND.TXT
echo option transfer binary>>FTPSND.TXT
ECHO send %1>>FTPSND.TXT
ECHO close>>FTPSND.TXT
ECHO exit>>FTPSND.TXT
winscp.com /script=ftpsnd.txt >>%2
And the error that is happening on the mkdir:
Error creating folder 'BEL'.
File or directory already exists.
(A)bort, (R)etry, (S)kip: Abort
My main problem is that if the directory does not exist, I need to create it, otherwise I skip that step and move on to the send.
Any ideas how I get around this?
EDIT
In response to Hackoo:
I failed to mention that this batch file is called from another batch file close to the end. When I used your code, I am not getting the file uploaded and the log shows:
ftp> Open ftp.adrive.com
Connected to ftp.adrive.com.
220 Username is your email address used for web interface
User (ftp.adrive.com:(none)):
331 Username OK, please send password.
230 Welcome xxxxx
ftp> prompt n
Interactive mode Off .
ftp> bin
200 TYPE changed to I.
ftp> MkDir /backup/companyfiles/IFC
550 File or directory already exists.
ftp> cd /backup/companyfiles/IFC
250 Changed directory OK.
ftp> mput D:\SSSAVES\sssbackup\TMPDIR\IFC_20160705141154.ZIP
200 PORT command OK.
150 Opening BINARY mode data connection for file IFC_20160705141154.ZIP.
It is not moving from this point and doing anything. I let it sit there for 2 hours just to make sure. The file is only 70mb in size so I doubt it would take that long.
EDIT #2
The file did eventually show up on Adrive, so I believe the ftp mput is working. It just doesn't seem to be releasing after it is sent
EDIT #3
I did change it from mput to put since I am only sending 1 file. That did not make a difference.
I created an account on ADrive.com and i created this script, just give a try
#echo off
Title Multiple file Upload by Hackoo on adrive
Color 0A
::****** Settings for FTP ************
Set FTPSERVER=ftp.adrive.com
Set USER=Your Login
Set Password=Your Password
Set LocalFolder=C:\Hackoo
Set RemoteFolder=/backupFolder
::************************************
::--- FTP commands below here ---
> ft.do echo Open %FTPSERVER%
>> ft.do echo %USER%
>> ft.do echo %Password%
>> ft.do echo prompt n
>> ft.do echo bin
>> ft.do echo lcd %LocalFolder%
>> ft.do echo MkDir %RemoteFolder%
>> ft.do echo cd %RemoteFolder%
>> ft.do echo mput "*.*"
>> ft.do echo disconnect
>> ft.do echo bye
::************************************
ftp -s:ft.do
del ft.do
Pause
Can you try with this vbscript and tell me if it upload or not this file with 70Mb in size :
set objShell = CreateObject("WScript.Shell")
Login = "Your Username"
'If your username contains the # symbol, and your web browser does not support this, you can substitute for the +
Login = Replace(Login,"#","+")
Password = "Your Pass"
FTPSERVER = "ftp.server.com"
RemoteFolder = "RemoteFolderName"
FTPURL = "ftp://"& Login &":"& Password &"#"& FTPSERVER &"/"& RemoteFolder
Connect2FTP = objShell.run("Explorer "& FTPURL ,1,False)
I have done an old vbscript to deal like that
Description :
You are on a different computer than you, either with friends or in a cybercafe?
You want to add, modify, delete files or folders on your FTP server?
No chance, you do not have programs on hand as FTP clients like (FileZilla, CuteFTP, FlashFXP. Etc ...) to access your Private FTP server !
No problem => FTP Explorer is the solution to turn your web browser or windows explorer in your FTP client !
I'd just translate this old french version to english version !
Hope that can help you !
Titre = "FTP EXPLORER © Hackoo © 2016"
Set objIE = CreateObject( "InternetExplorer.Application" )
objIE.Navigate "about:blank"
objIE.Document.Title = Titre
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 320
objIE.Height = 390
ScreenWidth = objIE.document.ParentWindow.screen.width
ScreenHeight = objIE.document.ParentWindow.screen.height
objIE.Left = (ScreenWidth - objIE.Width ) \ 2
objIE.Top = (ScreenHeight - objIE.Height) \ 2
Do While objIE.Busy
WScript.Sleep 200
Loop
objIE.Document.Body.InnerHTML = "<div align=""center""><p><h3 style='color:Red'>UserName " _
& "<br><input type=""text"" style='color:Blue' size=""20"" " _
& "id=""Login"" value=""put your user name here""></h3></p>"_
& "</p><p><h3 style='color:Red'>Password<br><input type=""password"" style='color:Blue' value=""Put your password here"" size=""20"" " _
& "id=""Password""></h3></p><p><input type=" _
& """hidden"" id=""OK"" name=""OK"" value=""0"">" _
& "<h3 style='color:Red'>FTP Server " _
& "<br><input type=""text"" style='color:Blue' size=""20"" " _
& "id=""FTPSERVER"" value=""ftp.server.com""></h3>"_
& "<br><h3 style='color:Red'>Remote Folder "_
& "<br><input type=""text"" style='color:Blue' size=""20"" " _
& "id=""DossierDistant"" value=""/www""></h3></p>"_
& "<input type=""submit"" value="" Browse your FTP Folder"" " _
& "onclick=""VBScript:OK.Value=1""></p></div>"
objIE.Document.Body.Style.overflow = "auto"
objIE.Document.body.style.backgroundcolor="lightGreen"
objIE.Visible = True
objIE.Document.All.Password.Focus
On Error Resume Next
Do While objIE.Document.All.OK.Value = 0
WScript.Sleep 200
If Err Then
IELogin = Array( "", "" )
objIE.Quit
Set objIE = Nothing
wscript.quit
End if
Loop
On Error Goto 0
Set ws = CreateObject("wscript.Shell")
Login = objIE.Document.All.Login.Value
Login = Replace(Login,"#","+")'If your username contains the # symbol, and your web browser does not support this, you can substitute for the +
Password = objIE.Document.All.Password.Value
FTPSERVER = objIE.Document.All.FTPSERVER.Value
DossierDistant = objIE.Document.All.DossierDistant.Value
URL = "ftp://"&Login&":"&Password&"#"&FTPSERVER&"/"&DossierDistant
Connect2FTP = ws.run("Explorer "& URL ,1,False)
objIE.Quit
ws.Popup "Connecting to "&qq(FTPSERVER)&" is in progress ..........",3,"Connecting to "&qq(FTPSERVER)&" is in progress ..........",64
Set objIE = Nothing
Set ws = Nothing
Close("iexplore.exe")
'****************************************************
Sub Close(Process)
Set Ws = CreateObject("Wscript.Shell")
Command = "cmd /c Taskkill /F /IM "&Process&""
Execution = Ws.Run(Command,0,True)
End Sub
'****************************************************
Function qq(strIn)
qq = Chr(34) & strIn & Chr(34)
End Function
'****************************************************
Related
Excel vba plink issue
I'm trying to get Excel VBA to run a list of commands on a Linux server. I used the following: Set objShell = CreateObject("WScript.Shell") cmd = plink & " -ssh -P 22 " & ip & " -l " & username & " -i " & ppk & " -m " & commands_file & " -t " Set oEx = objShell.Exec(cmd) where commands_file contains the following: sudo su - root /opt/ibm/ccm/collectLogs.sh When I run it the VB script appears a command line for a while and after it disappears without appearing to run the given instructions on commands_file. Where is the error? Please let me know. I'd like to have a command window opened and see it run the collectLogs without it closing after finished.
How do I use awk under cygwin to print fields from an excel spreadsheet?
We seem to be seeing more and more questions about executing awk on Excel spreadsheets so here is a Q/A on how to do that specific thing. I have this information in an Excel spreadsheet "$D/staff.xlsx" (where "$D" is the path to my Desktop): Name Position Sue Manager Bill Secretary Pat Engineer and I want to print the Position field for a given Name, e.g. output Secretary given the input Bill. I can currently save as CSV from Excel to get: $ cat "$D/staff.csv" Name,Position Sue,Manager Bill,Secretary Pat,Engineer and then run: $ awk -F, -v name="Bill" '$1==name{print $2}' "$D/staff.csv" Secretary but this is just a small part of a larger task and so I have to be able to do this automatically from a shell script without manually opening Excel to export the CSV file. How do I do that from a Windows PC running cygwin?
The combination of the following VBS and shell scripts create a CSV file for each sheet in the Excel spreadsheet: $ cat xls2csv.vbs csv_format = 6 Dim strFilename Dim objFSO Set objFSO = CreateObject("scripting.filesystemobject") strFilename = objFSO.GetAbsolutePathName(WScript.Arguments(0)) If objFSO.fileexists(strFilename) Then Call Writefile(strFilename) Else wscript.echo "no such file!" End If Set objFSO = Nothing Sub Writefile(ByVal strFilename) Dim objExcel Dim objWB Dim objws Set objExcel = CreateObject("Excel.Application") Set objWB = objExcel.Workbooks.Open(strFilename) For Each objws In objWB.Sheets objws.Copy objExcel.ActiveWorkbook.SaveAs objWB.Path & "\" & objws.Name & ".csv", csv_format objExcel.ActiveWorkbook.Close False Next objWB.Close False objExcel.Quit Set objExcel = Nothing End Sub . $ cat xls2csv PATH="$HOME:$PATH" # the original XLS input file path components inXlsPath="$1" inXlsDir=$(dirname "$inXlsPath") xlsFile=$(basename "$inXlsPath") xlsBase="${xlsFile%.*}" # The tmp dir we'll copy the XLS to and run the tool on # to get the CSVs generated tmpXlsDir="/usr/tmp/${xlsBase}.$$" tmpXlsPath="${tmpXlsDir}/${xlsFile}" absXlsPath="C:/cygwin64/${tmpXlsPath}" # need an absolute path for VBS to work mkdir -p "$tmpXlsDir" trap 'rm -f "${tmpXlsDir}/${xlsFile}"; rmdir "$tmpXlsDir"; exit' 0 cp "$inXlsPath" "$tmpXlsDir" cygstart "$HOME/xls2csv.vbs" "$absXlsPath" printf "Waiting for \"${tmpXlsDir}/~\$${xlsFile}\" to be created:\n" >&2 while [ ! -f "${tmpXlsDir}/~\$${xlsFile}" ] do # VBS is done when this tmp file is created and later removed printf "." >&2 sleep 1 done printf " Done.\n" >&2 printf "Waiting for \"${tmpXlsDir}/~\$${xlsFile}\" to be removed:\n" >&2 while [ -f "${tmpXlsDir}/~\$${xlsFile}" ] do # VBS is done when this tmp file is removed printf "." >&2 sleep 1 done printf " Done.\n" >&2 numFiles=0 for file in "$tmpXlsDir"/*.csv do numFiles=$(( numFiles + 1 )) done if (( numFiles >= 1 )) then outCsvDir="${inXlsDir}/${xlsBase}.csvs" mkdir -p "$outCsvDir" mv "$tmpXlsDir"/*.csv "$outCsvDir" fi Now we execute the shell script which internally calls cygstart to run the VBS script to generate the CSV files (one per sheet) in a subdirectory under the same directory where the Excel file exists named based on the Excel file name (e.g. Excel file staff.xlsx produces CSVs directory staff.csvs): $ ./xls2csv "$D/staff.xlsx" Waiting for "/usr/tmp/staff.2700/~$staff.xlsx" to be created: .. Done. Waiting for "/usr/tmp/staff.2700/~$staff.xlsx" to be removed: . Done. There is only one sheet with the default name Sheet1 in the target Excel file "$D/staff.xlsx" so the output of the above is a file "$D/staff.csvs/Sheet1.csv": $ cat "$D/staff.csvs/Sheet1.csv" Name,Position Sue,Manager Bill,Secretary Pat,Engineer $ awk -F, -v name="Bill" '$1==name{print $2}' "$D/staff.csvs/Sheet1.csv" Secretary Also see What's the most robust way to efficiently parse CSV using awk? for how to then operate on those CSVs. See also https://stackoverflow.com/a/58879683/1745001 for how to do the opposite, i.e. call a cygwin bash command from a Windows batch file.
Append or put variable within string in vbscript?
I am wanting to include the variable domainUser within the quoted command sent to the commandline but I am not having any luck. What I am trying to accomplish is to create a log file titled with their domain name but I keep getting errors or just getting a txt file with no title. Dim domainUser domainUser = Example123 objInParam.Properties_.Item("CommandLine") = "cmd /c ECHO Test >> c:\UserLogs\"""domainUser""".txt" So line 4 would be read like this (or whatever domain user I put in on line 2)... objInParam.Properties_.Item("CommandLine") = "cmd /c ECHO Test >> c:\UserLogs\Example123.txt"
You need concatenation to splice a variable's content into a string and double double quotes to put double quotes into it: >> Dim domainUser >> domainUser = "Example123" >> Dim cmd >> cmd = "cmd /c ECHO Test >> ""c:\UserLogs\" & domainUser & ".txt""" >> WScript.Echo cmd >> cmd /c ECHO Test >> "c:\UserLogs\Example123.txt"
How to enter multiple line of code in CMD from VBA?
I want to open a cmd.exe and then execute a few lines of code. I searched the web for some examples. Code I tried modifying: strToPrint = "Hello World!" Shell "cmd.exe /K echo " & strToPrint, vbNormalFocus I found How to write message to command window from VBA? I tried multiple lines of coding, but the lines are executed in different command windows: Sub CMD_VBA_Script() Shell "cmd.exe /K echo Hello World!", vbNormalFocus Shell "cmd.exe /K color 0a", vbNormalFocus End Sub I understand when I call the Shell two times, that it will execute two times. My goal is to call the following script from VBA: #echo off title Matrix color 0a mode 1000 :a echo %random%%random% goto a How can I execute multiple lines of code from VBA in command prompt?
MyFile = "C:\cmdcode.bat" fnum = FreeFile() Open MyFile For Output As #fnum Print #fnum, "#echo off" Print #fnum, "title Matrix" Print #fnum, "color 0a" Print #fnum, "mode 1000" Print #fnum, "" Print #fnum, ":a" Print #fnum, "echo %random%%random%" Print #fnum, "goto a" Close #fnum ' Run bat-file: Shell MyFile, vbNormalFocus ' optional, remove bat-file: Kill "C:\cmdcode.bat" So in short. You need to create a bat-file that you run. If you don't need the bat-file after it's done you can delete it with Kill
You can write something like this - Call Shell("cmd.exe /c "cd C:\Users\username\local\temp\" & " && temp.vbs" & " && mkdir newfolder") This executes 3 lines of command: Change directory Execute a vbs file Make a new folder
It looks like you want to execute a Command Prompt Batch file - batches are stateful, so simply executing each line separately is not going to have the same effect as executing the batch as a whole. Two other alternative approaches involve faking batch execution by instructing an interactive instance of cmd.exe to execute commands as-they're-entered by some automated process: either sending window messages, or piping into the cmd process' stdin stream. I do not recommend either of these approaches because of their inherent flakiness (i.e. dependency on undocumented behavior) So the best approach would be to just execute a batch file as it's intended - you would need to write the batch to a temporary file first, and then execute it: Using the code from here: https://support.microsoft.com/en-us/kb/195763 Dim tempFileName As String tempFileName = CreateTempFile("SomeBatch.cmd") WriteToBatchFile( tempFileName ) ' you will have to write to the temp batch file yourself here Shell "cmd.exe /c """ & tempFileName & """", vbHide, True ' Run the batch file, then cmd.exe will terminate. The Shell function will block until cmd is closed Kill tempFile ' delete the temp batch file
Use "cmd.exe /K" option, and '&' to connect multiple commands. In C:\Users\%USERNAME%, create test.bat with two simple commands: echo %PATH% dir Here is the complete sample: Sub Demo_Multi_Commands() Cmd1 = "cd " & Environ("USERPROFILE") Cmd2 = "test.bat" Connector = " & " Commands = "cmd.exe /K " & Cmd1 & Connector & Cmd2 & Connector & "systeminfo" Debug.Print Commands pid = Shell(Commands, vbNormalFocus) End Sub Environment: Windows 10 Enterprise, VBA 7.1
UNIX ZIP(1L) doesn't include top Directory of Application
I made, better I rummage together an AppleScript that results encrypted zip Files. It works except for Applications. If I expand the Archiv it is not an Application anymore. How can I compress valid Applications? tell application "Finder" set theItem to ((choose file) as alias) set itemPath to quoted form of POSIX path of theItem set fileName to name of theItem set theFolder to POSIX path of (container of theItem as alias) set zipFile to quoted form of (theFolder & fileName & ".zip") display dialog "Enter password" default answer "" buttons {"OK"} default button 1 set thePassword to (text returned of result) end tell set cmd to "zip -P " & thePassword & " -rj " & zipFile & " " & itemPath & " -x *.DS_Store" do shell script cmd
Check the -y option for zip. It may be what you need. From iPhone: Compressing .app files in command line (Mac OS X) removes CodeSigning