Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have two <strong>Powershell script</strong>, the first one help me to download <strong>ftp</strong> files from <strong>China</strong>:</p> <p><strong>Download FTP script</strong></p> <pre><code># Parametros param([string]$url, [string]$user, [string]$pass, [string]$folder, [string]$fecpro) if (!$fecpro) { $date = Get-Date $date = $date.AddDays(-1) $fecpro = '{0:yyyyMMdd}' -f $date } $FtpServer = "ftp://$url/$fecpro" $Username = $user $Password = $pass $RemoteFolder = $FtpServer if (!$folder) { $LocalFolder = $pwd.path + "\" } else { $LocalFolder = $folder + "\" if (-not(Test-Path -Path $LocalFolder)) { New-Item -ItemType Directory -Force -Path $LocalFolder } } Write-Host "Searching *.zip files from $RemoteFolder..." $existfiles = gci $LocalFolder | Where-Object { $_.name -like "*.zip" } $cntFile = 0 $totFiles = 1 $listFiles = @(0)*$totfiles $listFiles[1] = "cs2-" + $fecpro + "-6004-0000-1.zip" $existfiles = gci $LocalFolder | Where-Object { $_.name -like "*.zip" } do { try { $f_exist = $false $cntFile = $cntFile + 1 if ($existfiles) { foreach($file in $existfiles) { $tmpname = $file.name.ToString() $bool = $listFiles[$cntFile].CompareTo($file.name) if ($bool -eq 0) { $f_exist = ($f_exist -or $true) } else { $f_exist = ($f_exist -or $false) } } } if (!$f_exist -and $rescnt['CNT'] -eq 0) { $ftpfile = $RemoteFolder + "/" + $listFiles[$cntFile] $FTPRequest1 = [System.Net.FtpWebRequest]::Create($ftpfile) $FTPRequest1.Credentials = New-Object System.Net.NetworkCredential($Username,$Password) $FTPRequest1.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile $FTPRequest1.UsePassive = $true $FTPRequest1.UseBinary = $true $FTPRequest1.KeepAlive = $false $destfile = $LocalFolder + $listFiles[$cntFile] $file = New-Object IO.FileStream ($destfile, [IO.FileMode]::Create) $FTPResponse = $FTPRequest1.GetResponse() $ResponseStream = $FTPResponse.GetResponseStream() [byte[]] $buffer = New-Object byte[] 64 $FTPReader = $ResponseStream.Read($buffer, 0, 64) while($FTPReader -ne 0){ $FTPReader = $ResponseStream.Read($buffer,0, 64) $file.Write($buffer,0,$FTPReader) } Write-Host "File $ftpfile is downloaded in local folder." $file.Close() $FTPReader.Close() $FTPResponse.Close() $ResponseStream.Close() } else { Write-Host "The file $name already exists in local folder." } } catch { if ($file) { $file.Close() } } } while ($cntFile -lt $totFiles+1) </code></pre> <p>My second script unzip the files using unzip.exe that comes with <strong>Oracle client</strong>. (%ORACLE_HOME%\product\10.2.0\client_1\BIN)</p> <p><strong>Unzip files script</strong></p> <pre><code>param([string]$folder_origen, [string]$folder_destino, [string]$fecpro) $P_FOLDER = $folder_origen + "\" $P_DESTINO = $folder_destino + "\" if (!$fecpro) { $date = Get-Date $date = $date.AddDays(-1) $fecpro = '{0:yyyyMMdd}' -f $date } Write-Host "Searching *.zip files in $P_FOLDER" # Inicio del programa $LocalFolder = $P_FOLDER + "*$fecpro*.zip" $filelocation = gci $LocalFolder foreach ($file in $filelocation){ if (($file) -and ($file.length -gt 0kb)) { $shell = new-object -com shell.application $filename = $file.name.ToString() $split = $filename.Split(".") $dest = $P_DESTINO + $split[0] If (!(Test-Path $dest)) { New-Item $dest -Type Directory } $orifile = $P_FOLDER + $filename $time = "{0:hh_mm_ss.ffff}" -f (get-date) $prefile = "d." + (get-date).ToShortDateString() + ".t." + $time $prefile = $prefile -replace "/", "_" $filename = $prefile + ".f." + $filename $P_DESTZIP = $P_FOLDER + "proc" + "\" If (!(Test-Path $P_DESTZIP)) { New-Item $P_DESTZIP -Type Directory } #Copy-Item $orifile "$P_DESTZIP$prefile_$filename" $zipname = $orifile #"$P_DESTZIP$prefile_$filename" $zip = $shell.NameSpace($zipname) $destn = $shell.Namespace($dest) unzip -o -qq $zipname "*$fecpro*afsbjdtl.*" "*$fecpro*afgnled.bin" -d $dest Write-Host "$orifile was renamed and unzipped." } else { Write-Host "Zip files not found in the folder." } } </code></pre> <p>I search files to extract with a <strong>pattern</strong> when i could use filters like the <strong>size</strong> of file, the <strong>name</strong>, the <strong>extension</strong> and it's very fast.</p> <p>Finally about load i sugest the command <strong>LOAD DATA</strong> too. It's have the best performance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload