Need to list the file names in remote server using sftpc - powershell

I need to list the file names in a remote server using the PSFTP command.
sftpc -profile=remote_server_profile.tlp -cmd=ls location
This command is not giving any output. Does anyone know what may cause this?

Related

Unable to generate word output in DITA-OT if the input argument has an UNC path

I am trying to execute DITA-OT commands using JAVA application.
My DITA-OT sits at a separate location (application server WILDFLY) and the input files are on some other server. I'm trying to generate a word output but I'm getting an error "uri has an authority component"
The following is my command that I am trying to execute
cmd /C dita --input="\\<MACHINE_NAME>\FileServer\temp\dita-ot_00002_00001059387483239798817621042\00002_0000081949" --output="\\<MACHINE_NAME>\FileServer\temp\dita-ot_00002_00001059387483239798817621042\sc_report.docx" --format=docx
I added an issue on the DITA OT issues list:
https://github.com/dita-ot/dita-ot/issues/3673
Maybe in the meantime you can map the UNC path to a local drive and publish this way.

Run a script via FTP connection from PowerShell

I have made a script that does a really basic task, it connects to a remote FTP site, retrieves XML files and deletes them afterward.
The only problem is that in the past we lost files because they were added when the delete statement was run.
open ftp.site.com
username
password
cd Out
lcd "E:\FTP\Site"
mget *.XML
mdel *.XML
bye
To prevent this from happening, we want to put a script on the FTP server (rename-files.ps1). The script will rename the *.xml files to *.xml.copy.
The only thing is I have no clue how to run the script through my FTP connection.
Some, but very few, FTP servers support SITE EXEC command. In the very rare case that your FTP server does support it, you can use:
quote SITE EXEC powershell rename-files.ps1
Though, in most cases, you cannot execute anything on the FTP server, if FTP is the only way you can access the server. You would have to use another method to execute the script, like SSH, PowerShell Remoting, etc.
But your problem has other solutions:
rename files using FTP; or
delete only the files that were downloaded.
Both are doable, but you will need better FTP client than Windows ftp.exe.
See for example A WinSCP script to download, rename, and move files.
Or you can do it like:
Run ftp.exe once to retrieve list of files;
Process the list in PowerShell to generate an ftp script with get and del commands for specific files (without wildcard);
Run ftp.exe again with generated script.
Actually you do not need to use ftp.exe in PowerShell. .NET assembly has its own FTP implementation: FtpWebRequest.

SqlCompare command line remote server

I am trying to use the sqlcompare command line utility to compare a local database and a remote database but I am having difficulty doing this.
I would like to specify a connection string or some way to connect to the remote server (Destination)
Here is the command I have so far:
sqlcompare /Database1:RootDev /Database2:RootProd /scriptFile:"_build\changes.sql" /f
You'll want something along the lines below, using the switches /Server1 and /Server 2 to specify the servers.
sqlcompare /Server1:local\SQL2008 /Database1:RootDev /Server2:remote\SQL2008 /Database2:RootProd /scriptFile:"_build\changes.sql"
Full details on the docs

Using Netsh with PsExec

I'm trying to dump DHCP settings from an older server thats being decommissioned. I ran the command fine while on the actual server but when trying to run it using psexec remotely, it keeps failing. The command is: psexec \\$source netsh dhcp server \\$source dump>$dhcpSettings
$source = the server being decommissioned
$dhcpSettings = the path to save the dumped settings
I've tried all sorts of combinations of encapsulating quotation marks but still nothing. the errors I'm getting is, "The system cannot find the file specified" and "The system cannot find the path specified"
EDIT: So I got rid of the path to save the dumped settings and now it works. But how should I format the command so that it'll save the settings to the remote computer's C:\USER.SET\LOG directory?
One solution might be to bundle the command you want to run and the stdout redirection into a single line cmd file and use PsExec -c or -f to copy and execute that file on the remote system. As an example
Create a line cmd file named DHCPSettings.cmd with the following in it and save it to C:\temp\:
netsh dhcp server \\localhost dump >c:\user.set\log\dhcpsetting.log
Then use
psexec \\$source -c c:\temp\DHCPSettings.cmd
You did not really provide any code to go by and I am not sure I understand the all requirements and constraints you have, so consider this as an idea; not the exact commands you need to run. Hope it helps.

Send data to putty in powershell

I have powershell script that open putty.exe in process and i want to send data to this process, how can i do that???
PLEASE HELP!
The process:
$solExe = [diagnostics.process]::start("putty.exe", "-raw -P 2000 127.0.0.1")
The command line interface for putty is plink.exe. You can use plink to send commands over ssh.
For example:
PS C:> c:\progra~2\putty\plink.exe -i C:\credentials\mykeyfile.ppk root#myserver.com "ls";
Things to remember:
The first time you connect to a server, you'll have to add it to your registry, so this won't work in a non-interactive mode for brand new servers. There isn't a way to disable this.
The key file has to be in ppk format for plink.exe to recognize it. If yours is in pem format, use puttygen.exe to create a ppk file.
The path to the key file cannot contain any spaces, or the command above won't work.
If you want to send multiple commands at once, write them to a file and use the -m switch with plink.exe.
If you need to transfer files, you can use pscp.exe in a similar fashion.