psftp - Script file is not running - file

I have a script as sftpScript.bat and trying to run it in psftp. here is what I am trying in psftp (I have tried through cmd and then entering psftp):
psftp>open L2_SERVSEND#ecdev1.idev.fedex.com 60022 -b sftpScript.bat
Using username "L2_SERVSEND"
Connected to hostSSH server: password
Using keyboard-interactive authentication.
Enter password for L2_SERVSEND
Password:
Remote working directory is /L2_SERVSEND
psftp>
(I provided the password for the user when it asked!)
here is what my script file contains -
cd ..
cd L2_SERVRCV\APPTYPE
put sample.txt
put sample.txt
put sample.txt
put sample.txt
put sample.txt
put sample.txt
put sample.txt
Basically, I am tring to go inside the receiver's folder and then transfer sample.txt file to receiver i.e. L2_SERVRCV
I tried using -P while giving the port no but getting error "Port no invalid"; not sure why - that is not the priority as of now.
What I am expecting is that the script file should run and the sample.txt file should be transferred. But its not happening really!
P.S. - My all the files (psftp.exe, sftpScript.bat and the sample.txt) are in the same folder i.e. desktop.

Related

Using .bat or .lnk file to automate cmd and do user input

I would like to create a .bat or .lnk file (preferably a .lnk file) to automate the following sequence in cmd for me:
>runas /user:5CG95082M0\School "C:\Users\School\AppData\Local\Microsoft\Teams\Update.exe --processStart "Teams.exe""
Enter the password for 5CG95082M0\School: [my user password is an input here]
Attempting to start C:\Users\School\AppData\Local\Microsoft\Teams\Update.exe --processStart Teams.exe as user "5CG95082M0\School" ...
here is my question: how do I make the file to automatically input my user password when it is prompted I should do so?
Notice that the command is runas and that it waits for a user input. I've read that the use of echo to do that has been removed. As a proof (or is it?), note this when ran on cmd:
C:\Users\7329934>echo [my password] | runas /user:5CG95082M0\School "C:\Users\School\AppData\Local\Microsoft\Teams\Update.exe --processStart "Teams.exe""
Enter the password for 5CG95082M0\School:
Attempting to start C:\Users\School\AppData\Local\Microsoft\Teams\Update.exe --processStart Teams.exe as user "5CG95082M0\School" ...
RUNAS ERROR: Unable to run - C:\Users\School\AppData\Local\Microsoft\Teams\Update.exe --processStart Teams.exe
1326: The user name or password is incorrect.
Any thoughts?
Thanks

How can i insert the password from a text file using cmd?

I am trying to open a password protected Rar file with cmd and when it asks for a password I want it to
automatically insert the password stored in a text file.
How can I do that?
I suppose WinRAR has CLI for that stuff:
unrar x -p your_password your_rar_file.rar
Instead of your_password you can read from the file:
unrar x -p 'cat /path/to/passwdfile' your_rar_file.rar

When executing a batch file from python, the output is only the first line

I'm using the 'qwinsta' cmd command to get the session ID of a remote computer and output it to a textfile, so I create a new batch file and write the command then I try running the batch file through python but it only returns the first line of the output. When I run the batch file by simply double-clicking it it works properly.
Using python 2.7:
def run_qwinsta(self, computerName):
qwinsta_check = open("q.bat", "w")
qwinsta_check.write('PsExec -u <username> -p <password> \\\\' + computerName + ' qwinsta' + ' > "q.txt" ')
qwinsta_check.close()
os.system("q.bat")
Expected results:
SESSIONNAME USERNAME ID STATE TYPE DEVICE
>services 0 Disc
console <username> 1 Active
rdp-tcp 65536 Listen
Actual results:
SESSIONNAME USERNAME ID STATE TYPE DEVICE
I would recommend you to avoid writing the batchfile, If you can. You can execute your batch command from os.system(). Also you can try using subprocess (documentation here) and then redirecting the stdout and stderr to file.
EDIT:
PsExec is a good choice, but If you want another way, you can also use ssh.
You can run PsExec from os.system() and then write the response to text file on the remote machine. The default PsExec working directory is System32 there you can find your text file.
Tested code:
import os
os.system('Psexec \\\\SERVER cmd.exe /c "tasklist > process_list.txt"')
I used tasklist, because I don't have qwinsta on my remote machine.
If you want to store the PsExec response on your machine you can use subprocess and then redirect the stdout to text file.
Tested code:
import subprocess
process_list = open("process_list.txt", "w")
subprocess.call(['Psexec', '\\\\SERVER', 'tasklist'], stdout=process_list)
process_list.close()
Actually I used Python 3.x, because I don't have Python 2.x, but it should work on both.
If this still didn't solve your problem, please provide more details to your question!

sfdx force:data:bulk:upsert request contains invalid data

Having some trouble using the bulk:upsert command to update Account objects via a csv file. Hopefully someone can help me with this. Below is what I'm doing:
My csv file name is account.csv and it contains the following data:
Id,Name
0012F00000QjhC7QAJ,LimTest 1
0012F00000QjhkSQAR,LimTest 2
Below is the command that I'm running:
sfdx force:data:bulk:upsert -s Account -f account.csv -i Id -u dev
Above command gets submitted sucessfully. But the job failed.
The Batch status is as of below:
When I view the request, it looks like below:
It works after I manually created an empty file and copied and pasted the data into this new file. The original file, account.csv, was created using this command:
sfdx force:data:soql:query -q "select Id, Name from Account" -r csv -u dev > account.csv
I guess the above command must have created the file in a different encoding that the bulk:upsert does not know how to handle.

Batch for loop in psexec command

I'm trying to use a batch FOR loop inside a psexec. I need to make a script that offers me the possibility to choose the subfolders (I store the items in %list_of_items%) in %local_folder% that are needed to be copied with ncftpput on remote server. I cannot put the entire psexec inside the loop because I dont want to insert every time the password.
The piece of code:
psexec \\remote_server -u DOMAIN\user cmd /c FOR %%i IN "%list_of_items%" DO ("ncftpput -f c:\folders\file_with_creds.cfg -R remote_folder/ %local_folder%/%%i")
Example
I have:
%local_folder%\folder111
%local_folder%\folder222
%local_folder%\folder333
I choose to copy the items folder111 and folder333 so I store them in %list_of_items%. For every item in the list I need to run ncftpput to transfer to remote server the folder but doesnt work....
The error:
"folder111" was unexpected at this time.
cmd exited on remote_server with error code 1.
Can you help me please to find what I'm doing wrong?
Thank you.

Resources