I am currently attempting to use FileZilla Pro CLI on a Windows machine to connect and upload to a site in that is working in the Site Manager.
The issue is, the command below works perfectly when pasting it directly into the cmd line. However when saving it as a batch file, it simply just gets to the fzcli> prompt and then nothing happens.
The two line breaks are on purposes to override the requirement for a password and it works perfectly when pasted in.
Does anyone know if this is a cmd line issue, or if my commands need to be different to work in batch file mode?
fzcli
connect --site 0testsite01
put C:/inetpub/wwwroot/websites/sftp/files/customer/test-01.txt /test-sftp/testuser01/test/test-01-uploaded.txt
PAUSE
Your batch file executes fzcli in an interactive mode. The fzcli then waits for you to interactively enter the commands. Only after you would exit the fzcli, the batch file would continue. And fail, as it will try to execute connect as a batch file command. The fzcli does not know about the batch file. Nor does the batch file interpreter know about the fzcli commands.
It's a common misconception. You will find plenty of similar questions basically about scripting any tool that has its own commands. For example: sftp, ftp, psftp, winscp.
To provide commands to fzcli, it seems that you need to use --script switch. The fzcli documentation gives this example:
fzcli --mode standalone --script C:\Scripts\script-file
Related
I have gone through the following guide to set up an SSIS package to retrieve a text file located on an SFTP server:
https://www.mssqltips.com/sqlservertip/3435/using-sftp-with-sql-server-integration-services/
To summarize, the SSIS package executes PSFTP.exe (A PuTTY tool) which takes the necessary credentials to connect to the server. It also takes a batch file that it executes after connecting. This batch file contains the commands to retrieve the desired text file. To start from the guide, it simply contains a cmd command to change directory, and a get command to retrieve the file:
cmd DataDump
get TeleMarketingResults.txt
All of this works fine.
The issue arises when I try to make this batch file logic more complex as it does not seem to recognize basic keywords. For instance, I would like to modify it to retrieve the most recent file, so I tried adding this:
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
echo The most recently created file is %LAST%
but then I get these errors:
psftp: unknown command "for"
psftp: unknown command "echo"
If I execute the batch file manually in a local directory, it works. The issue only occurs when passing it as a parameter to PSFTP.exe. Why is this?
psftp script file can contain psftp commands only. for, set or dir are not psftp commands.
There's hardly any reasonable way to retrieve latest file using psftp. You would have to do it in two steps. First to retrieve listing and store it to a file. Then parse that file using some smart batch file commands to find the latest files. And then run psftp again to download that file. It is cumbersome and ineffective as it requires two connections.
You better use a more powerful SFTP client. For example it's trivial with my WinSCP SFTP client. See
Question WinSCP select most recent file or
WinSCP article Downloading the most recent file.
I'm trying to use WinSCP through script to synchronize a local folder with an FTP one.
I created a script a below
open ftp://<user>:<pw>#ftp.myserver.com/initFolder/
synchronize remote -delete C:\Data\backup /initFolder/
exit
And I run it with the command
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /log="C:\data\bin\log\WinSCP.log" /ini=nul /script="C:\data\bin\myScript.txt"
However, it appears nothing is happening. The command exists immediately with no message (either error or some processing / confirmation, etc).
Also no log file is created either.
What am I doing wrong?
Please advise
Indeed, with the command-line syntax you are using, WinSCP runs without any GUI.
If you are starting WinSCP from a console window (e.g. from Windows batch file), use winscp.com instead of winscp.exe. winscp.com is a console application. You will see any errors in the console.
Alternatively, you can add /console switch to winscp.exe command-line to make it open its own console window. Though you will rarely want this.
I am trying to run a batch file from Jenkins but I can't get it to run.
In the pre-build step I have entered the file I want to execute but I get the stacktrace shown below. Jenkins doesn't recognize the cmd command.
How can I fix this?
Your Linux Jenkins slave doesn't support cmd. In order to workaround it you have several options (from better to worse):
Add a Windows slave to Jenkins and run cmd from there.
Port your batch file to bash or similar and run it from your Linux Jenkins slave.
Add some kind of DOS emulator (Wine, DOSBox, DOSemu) in your Linux Jenkins slave.
My advice: If you know Linux & Bash or you have no control of Jenkins go for option 2. Otherwise go for option 1. Avoid option 3.
You're trying to run CMD on a LINUX machine. either change the slave you're running to Windows machine or migrate the Batch script to shell script.
Good luck!
I have a .bat file on my Windows machine. This .bat file uses plink.exe to connect to an Ubuntu machine and execute an .sh script. However, I get different behaviors on the script depending on how Plink is used:
log onto Ubuntu directly (in person) -- script succeeds
ssh via Bitvise client -- script succeeds
ssh via Plink (by calling plink.exe) and calling script from interactive shell (it's a Ubuntu shell within windows cmd.exe) -- script succeeds
ssh via .bat which then calls Plink -- script fails
The script fails w/ message:
error while loading shared libraries: libCint.so: cannot open shared object file: No such file or directory
Other posts seem to refer to installation/permission issues of libCint.so but I know this is not the case since the script works correctly in other instances as shown above.
Below is the plink.exe line from my .bat file:
plink.exe !plink_ssh_details! myscript
The above script fails when called this way via .bat file; again, note that it succeeds when called directly from the Ubuntu or when I -ssh directly into the Ubuntu via cmd.exe (using plink.exe) or Bitvise client. Any help would be appreciated.
In the other cases, you are using interactive sessions.
While the Plink uses non-interactive session by default, when you specify a command on its command-line.
Your script probably relies on some environment variables (like PATH) being set specifically.
It's quite probable that the variables are set only for interactive sessions. Probably because they are modified in a startup script that is executed (sourced) for the the interactive sessions only.
Solutions are:
Correct the startup scripts to modify the variables unconditionally (even for non-interactive sessions).
Modify the script not to rely on environment variables.
Or you can source the profile script, see Unable to run shell script with ktutil command from Windows using PLINK.
Force the Plink to use the interactive session using the -t switch
This is not a recommended solution, as using the interactive session to automate a command execution can bring you nasty side effects. See for example Is there a simple way to get rid of junk values that come when you SSH using Python's Paramiko library and fetch output from CLI of a remote machine?
Some more obscure SSH servers can also behave differently when "exec" channel is used to execute the command. See Executing command on Plink command line fails with "not found".
I had to hack a solution to work around this problem. Adding a "-i" option at the header of the bash script I was invoking from my .bat file did the trick:
#!/bin/bash -i
Note some warn of unwanted side effects (no mention of specifics tho...) when using this option. But calling this now interactive script from a remote ssh session (e.g. when using plink.exe from a Windows .bat file and passing inline commands to the Unix box) solves any issues regarding file/directory visibility & permission issues.
Note to plink users: if you're calling a script on Unix via plink and noticing that the script doesn't behave as expected...adding the "-i" may help debug/solve your problem. Again, note that some have claimed unwanted side-effects of this hack of which they/I'm unaware.
I am trying to run this command in jenkins after a MSbuild
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Y: is a mapped network drive. This runs fine in cmd.exe but when trying to run it in Jenkins, I am getting the error Invalid drive specification.
Here is the output from jenkins:
Time Elapsed 00:00:04.03
[trunk] $ cmd /c call C:\Windows\TEMP\hudson3389873107474371072.bat
C:\Program Files (x86)\Jenkins\workspace\trunk>xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Invalid drive specification
0 File(s) copied
C:\Program Files (x86)\Jenkins\workspace\trunk>exit 4
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
Any help would be appreciated.
I too had a similar issue once. Try granting the Jenkins service "Logon as This account" right under services.msc and make sure the account you type there is the same as the one you use for running cmd.exe.
These commands based on Java JAR files worked for me:
cmd
net use x: \\
xcopy "dist\" x:\ /Y
And that's it! I spent lot of time figure out this issue and nothing worked until I wrote CMD and NET USE!
Neither I didn't need to change permission on jenkins service nor use runas command.
But I must mention that everyone had read and write access to the network drive.
I had the same issue with my Windows Task running a batch file (I know it is not exactly same) where I tried to copy file to network location i.e. shared drive. I used the UNC path and mapped drive as well but the error was same. For me it was error number 4 - MS DOS error code.
The solution was to use net use command! Hope that it helps.
Easy fix for most things.
Make a batch command with what your trying to run, filename.bat with the command prompt text inside.
Make a normal windows shortcut for the batch command, edit the shortcuts advanced properties and check the "Run as admin" (tricky tricky).
Now run the filename.lnk shortcut from jenkins command line call, this will get you around all the jazz.
:)
The solution of adarshr (i.e., modifying the log on credentials of the service) has worked for me for a part of the problem: in my case, this allowed me to successfully check out a mercurial repository (using ssh protocol), which I could not do when using 'Local System account'.
However, I still have different behavior between running a command-line script or running the same script from a jenkins 'execute shell' script in the build section. In my case, I compile a Python extension. In Jenkins, I cannot import the extension (I don't see any error, but the execution simply stops, so I suspect it crashes).
If I uninstall the service and run the slave agent as a Java Web Start, I do get the same behavoir. It is a temporary fix for me, but it means that when I reboot the windows build machine, I have to manually re-start the Java Web Start application.
So -at least in my case- it is clear that this is a credential problem.
Credentials usage documentation: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
I've solved my issue with the CIFS plugin.
Faced similar issue and found two ways to solve.
Type 1:
Tell Jenkins about mapped drive.
1.Goto -> Manage Jenkins -> Script Console (Groovy Script).
2.Run below command
def mapdrive = "net use Y: \\\\copy_nework_address"
mapdrive.execute();
println "net use".execute().getText()
Type:2
1.Goto -> cmd -> run "net use" to know network address
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Copy_Network_Address\Extraction_Zone\Jenkins\" /E
Conclusion:- I prefer 2nd types as after every restart i should run Groovy Script.