Is it possible to transfer files over the network using CIM or WMI without SMB shares? [duplicate] - powershell

I need to read and write(update) some remote machine file.I am able to find the remote file using WMI(System.Management) but not able to do read or updation on that.
Any help would be appreciated.
Thanks
Himanshu

The WMI doesn't have any class (or method) to read or write the content of files. You may only retrieve the metadata (FileName, Date, Size) of the files using CIM_DataFile, or do tasks like Copy, Rename, Delete or Compress files.

RRUZ is correct: WMI cannot copy or create files over a network. This is because it would require credential "hopping":
http://msdn.microsoft.com/en-us/library/windows/desktop/aa389288%28v=vs.85%29.aspx
However, a workaround was recently created by Stackoverflow.com user Frank White in C#, and the WMI logic ports directly to VBS. Here's his solution:
WMI remote process to copy file
I ported it to a fully working VBScript:
https://stackoverflow.com/a/11948096/1569434

First check your file access in premmisions and set user "Everyone" to Full Control
then try it again.

Related

Export a CSV file from AS400 to my pc through Cl program

I want to export a database file that is created through a query, from the AS400 machine to my pc in the form of a csv file.
Is there a way to create that connection of the AS400 and my pc through a cl program?
An idea of what I want to do can be derived from the following code:
CLRPFM DTABASENAME
RUNQRY QRY(QRYTEST1)
CHGVAR VAR(&PATH) VALUE('C:\TESTS')
CHGVAR VAR(&PATH1) VALUE('C:\TESTS')
CHGVAR VAR(&CMD) VALUE(%TRIM(&PATH) *CAT '/DTABASENAME.CSV' !> &PATH !> &PATH1)
STRPCO PCTA(*YES)
STRPCCMD PCCMD(&CMD) PAUSE(*YES)
where I somehow get my database file, give the path that I want it to be saved in, in my pc , and lastly run the pc command accordingly
Take a look at
Copy From Query File (CPYFRMQRYF)
Which will allow you to create a database physical file from the query.
You may also want to look at
Copy To Import File (CPYTOIMPF)
Which will copy data from a database physical file to an Integrated File System (IFS) stream file (such as .CSV); which are the type of files you'd find on a PC.
ex:
CPYTOIMPF FROMFILE(MYLIB/MYPF) TOSTMF('/home/myuser/DTABASENAME.CSV') RCDDLM(*CRLF) DTAFMT(*DLM) STRDLM(*DBLQUOTE) STRESCCHR(*STRDLM) RMVBLANK(*TRAILING)
FLDDLM(',')
However, there's no single command to transfer data to your PC. Well technically, I suppose that's not true. If you configure a (SMB or NFS) file share on your PC and configure the IBM SMB or NFS client; you could in fact CPYTOIMPF directly to that file share or use the Copy Object (CPY) command to copy from the IFS to the network share.
If your PC has an FTP server available, you could send the data via the IBM i's FTP client. Similarly, if you have a SSH server on your PC, OpenSSL is available via PASE and SFTP or SCP could be used. You could also email the file from the i.
Instead of trying to send the file to your PC from the i. An easier solution would be to kick off a process on the PC that runs the download. My preference would be a Access Client Solution (ACS) data transfer.
You configure and save (as a .dtfx file) the transfer
Then you can kick it off with a
STRPCCMD cmd('java -jar C:\ACS\acsbundle.jar /plugin=download C:\testacs.dtfx')
More detailed information can be found in the Automating ACS Data Transfer document
The ACS download compoent is SQL based, so you could probably remove the need to use Query/400 at all
Assuming that you have your IFS QNTC mapped to your network domain. You could use the command CPYTOIMPF to copy the data directly from an IBMI DB2 file to a network directory.
This sample would result in a CSV file.
CPYTOIMPF FROMFILE(file) TOSTMF('//QNTC/servername or ip/path/filename.csv') STMFCCSID(*PCASCII) RCDDLM(*CRLF) STRDLM(*NONE)
Use the FLDDLM(';') option in addition to make semicolon separated values, omit it to use comma as value separator.

Talend: Using tfilelist to access files from a shared network path

I have a Talend job that searches a directory and then uploads it to our database.
It's something like this: dbconnection>twaitforfile>tfilelist>fileschema>tmap>db
I have a subjobok that then commits the data into the table iterates through the directory and movies files to another folder.
Recently I was instructed to change the directory to a shared network path using the same components as before (I originally thought of changing components to tftpfilelist, etc.)
My question being how to direct it to the shared network path. I was able to get it to go through using double \ but it won't read any of the new files arriving.
Thanks!
I suppose if you use tWaitForFile on the local filesystem Talend/Java will hook somehow into the folder and get a message if a new file is being put into it.
Now, since you are on a network drive first of all this is out of reach of the component. Second, the OS behind the network drive could be different.
I understand your job is running all the time, listening. You could change the behaviour to putting a tLoop first which would check the file system for new files and then proceed. There must be some delta check in how the new files get recognized.

How to fetch the files from local windows Share in Talend

How can I fetch a list of files from local Windows share (that requires credentials)? Is there anywhere I can specify a username/password to authenticate to that share location? using talend.
I don't know if it's an option for you because you didn't provide many context information.
But you could use the tSystem component to execute a command like this :
net use x: \\share\some /user:username password
Then use the tFileList component in order to retrieve the files from that directory.
I think you can mapped shared drive on your machine(where you want to execute the Talend job) then used that mapped drive location to get the files.

powershell - how to access shared folders via SFTP

I have VPN tunnel with 2 computers. When I connect with WinSCP (SFTP client) to second computer, I can see shared folders. The problem is, that I need to copy files from first computer to second with powershell script. Is it possible to access the shared folders via SFTP with Powershell? Thank you..
Since you're wanting to use PowerShell to manage the process, use PSCP.exe from the developer of PuTTY. That way you can do command line file transfers and don't have to worry about the GUI tools.

Can I copy files to a Network Place from a script or the command line? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Is it possible, in Windows XP, to copy files to a Network Place from the command line, a batch file or, even better, a PowerShell script?
What sent me down this road of research was trying to publish files to a WSS 3.0 document library from a user's machine. I can't map a drive to the library in question because the WSS site is only available to authenticate via NTLM on a port other than 80 or 443. I suppose I could alternately use the WSS web services to push the files out, but I'm really curious about the answer to this question now.
Using a batch file, you can both log on to the resource and copy the file:
The Batch File would contain the following:
net use \\{dest-machine}\{destfolder} {password} /user:{username}
copy {file} \\{dest-machine}\{destfolder}
e.g.
net use \\Development\myfolder mypassword /user:Administrator
copy newfile.c \\development\myfolder
If you are referring to a windows box, just use xcopy. It is pretty standard to have xcopy available.
xcopy src \\dest-machine\shared-library-name\dest
xcopy \\src-machine\shared-library-name\dest src
Powershell uses the abstraction of Providers to provide a common interface into datastores. These seem to stick with the common noun "Item", so you can get a complete list with man *item*. If you know another way to copy and otherwise work with data from a store, you might as well use it, but using the cmdlets provides a better "learn-once, use-often" approach. In your case you could:
Copy-Item test.txt -Destination \\dest-machine\share
Copy-item also supports the -Credential parameter if you need it.
"Network Places" doesn't really have an API, it's just a bunch of shortcuts, and the SharePoint share uses a Shell Extension, if I recall correctly.
All of that to say: accessing Sharepoint as a file system from PowerShell also requires an extension, the SharePoint Provider.
you could use the 'net' commands to authenticate and then copy the files.
copy src \\dest-machine\shared-library-name\dest
I'm not really sure exactly how to handle authentication if it's needed.
From what I'm seeing, it seems that it's not possible to directly access/ manipulate a Network Place from the command line, be it in PowerShell or the plain ol' command prompt.
#slipsec (#13899):
Thanks for the suggestion, but PowerShell doesn't support the port number in the destination path any more than the net use command does.
So the best thing I can figure to do in my particular situation is bite the bullet and buy something like WebDrive to enable drive mapping via WebDAV on non-standard ports, or do some different configuration (e.g. separate web app with a different IP address and host headers) in SharePoint to expose the site via NTLM on a standard port.
I could be wrong about this, but I think that neither Nick's robocopy solution or Nathan's copy command solution will work. Robocopy seems to want a mapped drive, which I can't do because it's not running on port 80 or 443, and Windows can't handle a path that includes the port in a UNC-style name:
copy src \\dest-machine:45000\shared-library-name\dest
I didn't see a NAnt task that would handle this situation, either.
I also know there are tools that will allow me to map WebDAV drives. I was more wondering if there was some way to make use of the Network Places that have been set up without using the GUI.
If it's something you need to script, you should consider NAnt.
It's a mainly used for build scripts, but it's very powerful and reasonably easy to get started with.
There's also NAntContrib and the nant ftp task which should help you out.
Yes you can. I suggest using a tool like robocopy.